diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..ceec6ee --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,53 @@ +name: Build container images + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + branches: + - master + pull_request: + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + platforms: linux/amd64,linux/arm64 + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + type=sha + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c14085c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM --platform=$BUILDPLATFORM golang:1.20 AS builder + +WORKDIR /workspace +COPY . /workspace + +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o annict-epgstation-connector ./cmd/annict-epgstation-connector + +FROM gcr.io/distroless/static:nonroot +WORKDIR / +COPY --from=builder /workspace/annict-epgstation-connector . +USER 65532:65532 + +ENTRYPOINT ["/annict-epgstation-connector"]