From cd66c94200950deaf5a8384b53083eceb0ca50b7 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Wed, 24 Apr 2024 12:50:10 +0200 Subject: [PATCH] Add github build pipeline --- .github/workflows/docker-build.yml | 49 ++++++++++++++++++++++++++++++ Dockerfile | 11 +++++-- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..a9166bf --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,49 @@ +name: publish + +on: + push: + tags: + - '*' + +jobs: + publish: + permissions: + packages: write + + runs-on: actuated + steps: + - uses: actions/checkout@master + with: + fetch-depth: 1 + + - name: Setup mirror + uses: self-actuated/hub-mirror@master + - name: Get TAG + id: get_tag + run: echo TAG=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV + - name: Get Repo Owner + id: get_repo_owner + run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" > $GITHUB_ENV + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to container Registry + uses: docker/login-action@v2 + with: + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + + - name: Release build + id: release_build + uses: docker/build-push-action@v4 + with: + outputs: "type=registry,push=true" + provenance: false + platforms: linux/amd64,linux/arm/v6,linux/arm64 + tags: | + ghcr.io/${{ env.REPO_OWNER }}/mini-mail-dev:${{ github.sha }} + ghcr.io/${{ env.REPO_OWNER }}/mini-mail-dev:${{ env.TAG }} + ghcr.io/${{ env.REPO_OWNER }}/mini-mail-dev:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 6b1e96c..8d77a21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,14 @@ -FROM node:20-slim AS frontend +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + +FROM node:21-slim AS frontend COPY . . RUN npm install && npm run build -FROM golang:1.21 +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21 WORKDIR /usr/src/app @@ -16,7 +20,8 @@ COPY go go COPY main.go . COPY --from=frontend dist dist -RUN go build -o /usr/bin/mini-mail-dev && \ +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -o /usr/bin/mini-mail-dev && \ rm -rf go main.go go.mod go.sum dist EXPOSE 1025/tcp