From b8baa5cf4f1a529b99f950347e66baff2873daae Mon Sep 17 00:00:00 2001 From: Cory Sanin Date: Thu, 9 Jan 2025 02:31:14 -0500 Subject: [PATCH] build app image --- .github/workflows/build-app-image.yml | 104 ++++++++++++++++++++++++++ Dockerfile | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-app-image.yml diff --git a/.github/workflows/build-app-image.yml b/.github/workflows/build-app-image.yml new file mode 100644 index 0000000..ef60317 --- /dev/null +++ b/.github/workflows/build-app-image.yml @@ -0,0 +1,104 @@ +name: MultiArchDockerBuild + +on: + push: + branches: + - master + tags: + - 'v*' + pull_request: + branches: + - master + + +jobs: + build_app_image: + name: Build app image + runs-on: ubuntu-latest + env: + DH_REGISTRY: docker.io + GH_REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + REPOSITORY: ${{ github.event.repository.name }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + with: + install: true + + - name: Login to DockerHub + if: startsWith(github.ref, 'refs/tags/v') + uses: docker/login-action@v3 + with: + registry: ${{ env.DH_REGISTRY }} + username: ${{ env.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.GH_REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for release Docker image + if: startsWith(github.ref, 'refs/tags/v') + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.DOCKER_USERNAME }}/${{ env.REPOSITORY }} + ${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Extract metadata for develop Docker image + if: "!startsWith(github.ref, 'refs/tags/v')" + id: meta-develop + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + + - name: Build and push release Docker image + if: startsWith(github.ref, 'refs/tags/v') + uses: docker/build-push-action@v6 + with: + target: deploy + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + platforms: linux/amd64,linux/arm64 + cache-from: type=gha,scope=${{ github.workflow }} + cache-to: type=gha,mode=max,scope=${{ github.workflow }} + + - name: Build and push develop Docker image + if: "!startsWith(github.ref, 'refs/tags/v')" + uses: docker/build-push-action@v6 + with: + target: deploy + push: true + tags: ${{ steps.meta-develop.outputs.tags }} + labels: ${{ steps.meta-develop.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha,scope=${{ github.workflow }} + cache-to: type=gha,mode=max,scope=${{ github.workflow }} diff --git a/Dockerfile b/Dockerfile index 5d708c0..d57fb8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /build COPY ./package*json ./ RUN npm ci --only=production --omit=dev -FROM docker:clie as deploy +FROM docker:cli as deploy WORKDIR /srv/abt