From 73a52722a86f50949261f14f07feba0db4c702ae Mon Sep 17 00:00:00 2001 From: Chaitanya Munukutla Date: Sat, 27 Apr 2024 11:23:10 +0530 Subject: [PATCH 1/2] Added Docker step Signed-off-by: Chaitanya Munukutla --- .github/workflows/pr.yaml | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 26 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 1e1d132..09309ee 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -162,3 +162,35 @@ jobs: - name: Build run: go build -ldflags="-s -w" -o microq main.go + + image: + name: Build Image + needs: + - build-linux-amd64 + - build-linux-arm64 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: false + tags: | + ghcr.io/c16a/microq:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2853e2a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Stage 1: Build the Go application (compiler and dependencies) +FROM golang:1.22.2 AS builder + +WORKDIR /app + +# Copy your Go source code +COPY go.mod ./ +COPY go.sum ./ +RUN go mod download + +COPY . . +RUN go build -ldflags="-s -w" -o microq github.com/c16a/microq + +# Stage 2: Production image (slim and optimized) +FROM scratch + +WORKDIR /app + +# Copy only the built binary from the builder stage +COPY --from=builder /app/microq ./ + +# Expose the port your application listens on (replace 8080 with your actual port) +EXPOSE 8080 + +# Set the command to execute your binary +CMD ["microq"] From 7e333af85fce91a883e4976eef8c98b862453e93 Mon Sep 17 00:00:00 2001 From: Chaitanya Munukutla Date: Sat, 27 Apr 2024 11:33:29 +0530 Subject: [PATCH 2/2] Add Docker build for PR merge Signed-off-by: Chaitanya Munukutla --- .github/workflows/push.yaml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index ab0a678..e897894 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -162,3 +162,35 @@ jobs: - name: Build run: go build -ldflags="-s -w" -o microq main.go + + image: + name: Build Image + needs: + - build-linux-amd64 + - build-linux-arm64 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ghcr.io/c16a/microq:latest \ No newline at end of file