name: Build and Push EdgeNode Docker Image on: push: tags: - 'v*' branches: - master - main pull_request: branches: - master - main workflow_dispatch: inputs: build_type: description: 'Build type (community or plus)' required: true default: 'community' type: choice options: - community - plus env: REGISTRY_GHCR: ghcr.io IMAGE_NAME_GHCR: ${{ github.repository }} REGISTRY_DOCKER: docker.io IMAGE_NAME_DOCKER: ${{ secrets.DOCKER_HUB_USERNAME }}/edge-node jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write strategy: matrix: include: - platform: linux/amd64 arch: amd64 - platform: linux/arm64 arch: arm64 steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY_GHCR }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Log in to Docker Hub if: github.event_name != 'pull_request' && secrets.DOCKER_HUB_USERNAME != '' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: | ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }} ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }} tags: | type=ref,event=branch type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,prefix={{branch}}- type=raw,value=latest,enable={{is_default_branch}} - name: Determine build type id: build_type run: | if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then echo "build_type=${{ inputs.build_type }}" >> $GITHUB_OUTPUT else echo "build_type=community" >> $GITHUB_OUTPUT fi - name: Build and push GHCR uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile platforms: ${{ matrix.platform }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-args: | VERSION=${{ github.ref_name }} BUILD_TYPE=${{ steps.build_type.outputs.build_type }} TARGETARCH=${{ matrix.arch }} publish-manifest: runs-on: ubuntu-latest needs: build if: github.event_name != 'pull_request' permissions: contents: read packages: write steps: - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY_GHCR }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Create manifest for GHCR run: | docker manifest create \ ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }} \ --amend ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }}-amd64 \ --amend ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }}-arm64 docker manifest push ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }} - name: Log in to Docker Hub if: secrets.DOCKER_HUB_USERNAME != '' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Create manifest for Docker Hub if: secrets.DOCKER_HUB_USERNAME != '' run: | docker manifest create \ ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }} \ --amend ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }}-amd64 \ --amend ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }}-arm64 docker manifest push ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }}