From b2f688641fcb57c7a29a5cee6d6ea791f4225416 Mon Sep 17 00:00:00 2001 From: KoCoder Date: Thu, 4 Jun 2026 23:45:43 +0200 Subject: [PATCH] New: Configure Dockerfile and Pipeline for deployment --- .dockerignore | 1 + .github/workflows/docker.yaml | 46 +++++++++++++++++++++++++++++++++++ Dockerfile | 32 ++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yaml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e38da20 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +settings.json diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..23609a9 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,46 @@ +name: Build and Push Docker Image + +on: + push: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + container: + image: quay.io/buildah/stable + options: --security-opt seccomp=unconfined --security-opt apparmor=unconfined --device /dev/fuse:rw --privileged + + env: + BUILDAH_ISOLATION: chroot + STORAGE_DRIVER: vfs + + steps: + - name: Install Node.js + run: dnf install -y nodejs git + + - uses: actions/checkout@v4 + with: + ssh-user: ${{ secrets.REGISTRY_USER }} + token: ${{ secrets.REGISTRY_PASSWORD }} + submodules: true + + - name: Login to Registry + run: buildah login -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.REGISTRY_PASSWORD }} git.kocoder.xyz + + - name: Generate Tag + id: tag + run: | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) + echo "value=${{ github.ref_name }}-$(date +%s)-${SHORT_SHA}" >> $GITHUB_OUTPUT + + - name: Buildah Build + run: | + buildah build -t ${{ steps.tag.outputs.value }} . + buildah tag ${{ steps.tag.outputs.value }} latest + + - name: Push Docker Images + run: | + buildah push ${{ steps.tag.outputs.value }} docker://git.kocoder.xyz/vt/financial-tracking-service:${{ steps.tag.outputs.value }} + buildah push latest docker://git.kocoder.xyz/vt/financial-tracking-service:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a986dab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM golang:1.26-bookworm AS base + +# Move to working directory /app +WORKDIR /app + +# Copy the go.mod and go.sum files to the /app directory +COPY go.mod go.sum ./ + +# Install dependencies +RUN go mod download + +# Copy the entire source code into the container +COPY . . + +# Build the application +RUN go build -o financial-tracking-service + +# Install goose migration tool +RUN GOBIN=/app go install github.com/pressly/goose/v3/cmd/goose@latest + +FROM golang:1.26-bookworm AS runner + +WORKDIR /app +COPY --from=base /app/financial-tracking-service /app/financial-tracking-service +COPY --from=base /app/goose /app/goose +COPY --from=base /app/sql/schema /app/sql/schema + +# Document the port that may need to be published +EXPOSE 8081 + +# Start the application +CMD ["/app/financial-tracking-service"]