From f7c69ad1cd9a218d2e1b85a1c64b6577fb307a15 Mon Sep 17 00:00:00 2001 From: mauricioromagnollo Date: Tue, 10 Oct 2023 22:10:56 -0300 Subject: [PATCH] ci: add publish pipeline --- .github/workflows/publish.yml | 35 +++++++++++++++++++++++++++++++++++ Dockerfile | 9 +++++++++ 2 files changed, 44 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 Dockerfile diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7834f9e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,35 @@ +name: Build and Publish Docker Image + +on: + push: + branches: + - master + +env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + +jobs: + build: + name: Build and Publish + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build the Docker image + run: | + docker build -t mauricioromagnollo/kafka-rest:latest . + + - name: Login to Docker Hub + run: | + echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin + + - name: Publish Docker Image to Docker Hub + if: success() + run: | + docker push mauricioromagnollo/kafka-rest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2e3a8aa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:1.20.6 as builder +WORKDIR /app +COPY . . +RUN GOOS=linux go build -ldflags="-w -s" -o bin/api cmd/api/main.go + +FROM scratch +COPY --from=builder /app/bin/api . +EXPOSE 8080 +CMD [ "./api" ] \ No newline at end of file