Merge pull request #43 from cozy-creator/dev #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Multi-Architecture Build | |
| on: | |
| push: | |
| branches: | |
| - master | |
| tags: | |
| - 'v[0-9]*.*.*' | |
| pull_request: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: cozycreator/gen-server | |
| jobs: | |
| build-x86: | |
| name: Build x86_64 Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Log into Docker Hub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract version | |
| id: version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Build and Push x86_64 Image | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64 . | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-amd64 | |
| docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-amd64 | |
| else | |
| docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64 | |
| fi | |
| build-arm64: | |
| name: Build ARM64 Image | |
| runs-on: | |
| group: default-public | |
| labels: linux-arm64 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Log into Docker Hub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract version | |
| id: version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Build and Push ARM64 Image | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64 . | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-arm64 | |
| docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-arm64 | |
| else | |
| docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64 | |
| fi | |
| create-manifest: | |
| name: Create Multi-Arch Manifest | |
| needs: [build-x86, build-arm64] | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' | |
| steps: | |
| - name: Extract version | |
| id: version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Log into Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Create and Push Manifest | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| # Create version manifest | |
| docker manifest create ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} \ | |
| --amend ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-amd64 \ | |
| --amend ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-arm64 | |
| docker manifest annotate ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-amd64 --os linux --arch amd64 | |
| docker manifest annotate ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-arm64 --os linux --arch arm64 | |
| docker manifest push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} | |
| else | |
| # Create latest manifest | |
| docker manifest create ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ | |
| --amend ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64 \ | |
| --amend ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64 | |
| docker manifest annotate ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64 --os linux --arch amd64 | |
| docker manifest annotate ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64 --os linux --arch arm64 | |
| docker manifest push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
| fi |