docker.yml (4252B)
1 --- 2 name: Build & Push 3 4 on: 5 push: 6 branches: 7 - main 8 - '*.feature' 9 - '*.fix' 10 tags: 11 - 'v*' 12 pull_request: 13 branches: 14 - main 15 16 jobs: 17 version: 18 name: Extract version 19 runs-on: ubuntu-latest 20 outputs: 21 version: ${{ steps.version.outputs.version }} 22 steps: 23 - name: Extract version 24 id: version 25 run: | 26 if [[ "${{ github.ref }}" == refs/tags/v* ]]; then 27 echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT 28 else 29 echo "version=latest" >> $GITHUB_OUTPUT 30 fi 31 32 build-binaries: 33 name: Build binaries 34 runs-on: ubuntu-latest 35 needs: version 36 strategy: 37 matrix: 38 include: 39 - name: linux-amd64 40 bin: udphole-linux-amd64 41 cross: false 42 43 - name: linux-arm64 44 arch: aarch64 45 bin: udphole-linux-arm64 46 cross: true 47 48 - name: linux-riscv64 49 arch: riscv64 50 bin: udphole-linux-riscv64 51 cross: true 52 53 steps: 54 - uses: actions/checkout@v4 55 56 - uses: finwo/dep@main 57 name: Install dep 58 59 - name: Install dependencies 60 run: dep install 61 62 - if: '!matrix.cross' 63 name: Build native 64 run: | 65 make -j udphole VERSION=${{ needs.version.outputs.version }} 66 strip udphole 67 mv udphole ${{ matrix.bin }} 68 69 - if: matrix.cross 70 uses: uraimo/run-on-arch-action@v3 71 name: Build cross 72 with: 73 arch: ${{ matrix.arch }} 74 distro: ubuntu24.04 75 githubToken: ${{ github.token }} 76 install: | 77 apt-get update -y 78 apt-get install -yq build-essential 79 run: | 80 make -j udphole VERSION=${{ needs.version.outputs.version }} 81 strip udphole 82 mv udphole ${{ matrix.bin }} 83 84 - name: Upload artifact 85 uses: actions/upload-artifact@v4 86 with: 87 name: ${{ matrix.bin }} 88 path: ${{ matrix.bin }} 89 retention-days: 1 90 91 docker: 92 runs-on: ubuntu-latest 93 needs: [version, build-binaries] 94 permissions: 95 contents: read 96 packages: write 97 98 steps: 99 - name: Checkout 100 uses: actions/checkout@v4 101 102 - name: Set up QEMU 103 uses: docker/setup-qemu-action@v3 104 105 - name: Set up Docker Buildx 106 uses: docker/setup-buildx-action@v3 107 108 - name: Download all artifacts 109 uses: actions/download-artifact@v4 110 with: 111 path: . 112 pattern: udphole-linux-* 113 merge-multiple: true 114 115 - name: Log in to Docker Hub 116 if: github.event_name != 'pull_request' 117 uses: docker/login-action@v3 118 with: 119 username: ${{ secrets.DOCKERHUB_USERNAME }} 120 password: ${{ secrets.DOCKERHUB_TOKEN }} 121 122 - name: Extract metadata 123 id: meta 124 uses: docker/metadata-action@v5 125 with: 126 images: docker.io/finwo/udphole 127 tags: | 128 type=ref,event=branch 129 type=ref,event=pr 130 type=semver,pattern={{version}} 131 type=semver,pattern={{major}} 132 type=semver,pattern={{major}}.{{minor}} 133 type=semver,pattern={{major}}.{{minor}}.{{patch}} 134 type=raw,value=latest,enable={{is_default_branch}} 135 136 - name: Build and push 137 uses: docker/build-push-action@v5 138 with: 139 context: . 140 platforms: linux/amd64,linux/arm64/v8,linux/riscv64 141 push: ${{ github.event_name != 'pull_request' }} 142 tags: ${{ steps.meta.outputs.tags }} 143 labels: ${{ steps.meta.outputs.labels }} 144 cache-from: type=gha 145 cache-to: type=gha,mode=max 146 build-args: VERSION=${{ needs.version.outputs.version }} 147 148 - name: Update Docker Hub description 149 if: github.event_name != 'pull_request' 150 uses: peter-evans/dockerhub-description@v5 151 with: 152 username: ${{ secrets.DOCKERHUB_USERNAME }} 153 password: ${{ secrets.DOCKERHUB_TOKEN }} 154 repository: finwo/udphole 155 short-description: "UDP hole punching proxy with RESP2 API | Source: https://github.com/finwo/udphole" 156 readme-filepath: DOCKER.md