|
| 1 | +name: Docker Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + publish: |
| 10 | + description: "Push image to GHCR" |
| 11 | + required: false |
| 12 | + default: false |
| 13 | + type: boolean |
| 14 | + image_name: |
| 15 | + description: "GHCR image name (without ghcr.io/), default: owner/masterhttprelayvpn" |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + docker-multiarch: |
| 25 | + name: Build Docker amd64+arm64 |
| 26 | + runs-on: ubuntu-latest |
| 27 | + if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true') |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Set up QEMU |
| 34 | + uses: docker/setup-qemu-action@v3 |
| 35 | + |
| 36 | + - name: Set up Docker Buildx |
| 37 | + uses: docker/setup-buildx-action@v3 |
| 38 | + |
| 39 | + - name: Login to GHCR |
| 40 | + uses: docker/login-action@v3 |
| 41 | + with: |
| 42 | + registry: ghcr.io |
| 43 | + username: ${{ github.actor }} |
| 44 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Resolve image and tags |
| 47 | + id: meta |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + set -euo pipefail |
| 51 | + owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') |
| 52 | + if [ -n "${{ github.event.inputs.image_name || '' }}" ]; then |
| 53 | + image="ghcr.io/${{ github.event.inputs.image_name }}" |
| 54 | + else |
| 55 | + image="ghcr.io/${owner}/masterhttprelayvpn" |
| 56 | + fi |
| 57 | +
|
| 58 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 59 | + tag="${{ github.ref_name }}" |
| 60 | + else |
| 61 | + tag="manual-${{ github.run_number }}" |
| 62 | + fi |
| 63 | +
|
| 64 | + { |
| 65 | + echo "image=$image" |
| 66 | + echo "tag=$tag" |
| 67 | + } >> "$GITHUB_OUTPUT" |
| 68 | +
|
| 69 | + - name: Build and push image |
| 70 | + uses: docker/build-push-action@v6 |
| 71 | + with: |
| 72 | + context: . |
| 73 | + file: ./Dockerfile |
| 74 | + platforms: linux/amd64,linux/arm64 |
| 75 | + push: true |
| 76 | + tags: | |
| 77 | + ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.tag }} |
| 78 | + ${{ steps.meta.outputs.image }}:latest |
0 commit comments