diff --git a/.github/workflows/dock_ci.yml b/.github/workflows/dock_ci.yml new file mode 100644 index 0000000..95f2767 --- /dev/null +++ b/.github/workflows/dock_ci.yml @@ -0,0 +1,53 @@ +name: Build Docker Image + +on: + push: + branches: + - "master" + paths-ignore: + - "README.md" + workflow_dispatch: + +jobs: + build-and-deploy: + 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 GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_PAT }} + + - name: Set GHCR_REPO and GHCR_OWNER env + run: | + echo "GHCR_OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV + echo "GHCR_REPO=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}" >> $GITHUB_ENV + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.GHCR_REPO }} + + - name: Build and push to GHCR + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + file: Dockerfile + push: true + tags: ${{ env.GHCR_REPO }}:latest + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eba834c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.23.0 AS builder +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 go build -o pansou main.go + +FROM scratch +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /app/pansou /app/pansou + +EXPOSE 8080 + +CMD ["/app/pansou"]