| 1 | name: CD |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: [main] |
| 6 | tags: ["v*"] |
| 7 | |
| 8 | env: |
| 9 | REGISTRY: ghcr.io |
| 10 | PLATFORMS: linux/amd64,linux/arm64 |
| 11 | |
| 12 | concurrency: |
| 13 | group: cd-${{ github.ref }} |
| 14 | cancel-in-progress: true |
| 15 | |
| 16 | jobs: |
| 17 | build-and-push: |
| 18 | name: Build and Push Docker Images |
| 19 | runs-on: ubuntu-latest |
| 20 | permissions: |
| 21 | contents: read |
| 22 | packages: write |
| 23 | strategy: |
| 24 | fail-fast: false |
| 25 | matrix: |
| 26 | include: |
| 27 | - image: gosuda/portal |
| 28 | context: . |
| 29 | file: Dockerfile |
| 30 | cache_scope: portal |
| 31 | - image: gosuda/portal-frontend |
| 32 | context: ./frontend |
| 33 | file: ./frontend/Dockerfile |
| 34 | cache_scope: frontend |
| 35 | - image: gosuda/portal-api |
| 36 | context: ./frontend |
| 37 | file: ./frontend/Dockerfile |
| 38 | target: api |
| 39 | cache_scope: portal-api |
| 40 | |
| 41 | steps: |
| 42 | - name: Checkout code |
| 43 | uses: actions/checkout@v6 |
| 44 | |
| 45 | - name: Log in to Container Registry |
| 46 | uses: docker/login-action@v3 |
| 47 | with: |
| 48 | registry: ${{ env.REGISTRY }} |
| 49 | username: ${{ github.actor }} |
| 50 | password: ${{ secrets.GITHUB_TOKEN }} |
| 51 | |
| 52 | - name: Set up QEMU |
| 53 | uses: docker/setup-qemu-action@v3 |
| 54 | |
| 55 | - name: Set up Docker Buildx |
| 56 | uses: docker/setup-buildx-action@v3 |
| 57 | |
| 58 | - name: Extract metadata |
| 59 | id: meta |
| 60 | uses: docker/metadata-action@v5 |
| 61 | with: |
| 62 | images: ${{ env.REGISTRY }}/${{ matrix.image }} |
| 63 | tags: | |
| 64 | type=raw,value=latest,enable={{is_default_branch}} |
| 65 | type=semver,pattern={{version}} |
| 66 | type=semver,pattern={{major}}.{{minor}} |
| 67 | type=semver,pattern={{major}} |
| 68 | type=sha,enable=true,prefix=sha-,suffix=,format=short |
| 69 | |
| 70 | - name: Build and push Docker image |
| 71 | uses: docker/build-push-action@v6 |
| 72 | with: |
| 73 | context: ${{ matrix.context }} |
| 74 | file: ${{ matrix.file }} |
| 75 | target: ${{ matrix.target }} |
| 76 | platforms: ${{ env.PLATFORMS }} |
| 77 | push: true |
| 78 | tags: ${{ steps.meta.outputs.tags }} |
| 79 | labels: ${{ steps.meta.outputs.labels }} |
| 80 | cache-from: type=gha,scope=${{ matrix.cache_scope }} |
| 81 | cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }} |
| 82 | |
| 83 | release-binaries: |
| 84 | name: Build and Release Tunnel Binaries |
| 85 | if: startsWith(github.ref, 'refs/tags/v') |
| 86 | runs-on: ubuntu-latest |
| 87 | permissions: |
| 88 | contents: write |
| 89 | |
| 90 | steps: |
| 91 | - name: Checkout code |
| 92 | uses: actions/checkout@v6 |
| 93 | |
| 94 | - name: Set up Go |
| 95 | uses: actions/setup-go@v6 |
| 96 | with: |
| 97 | go-version-file: go.mod |
| 98 | cache: true |
| 99 | |
| 100 | - name: Build tunnel binaries |
| 101 | shell: bash |
| 102 | run: | |
| 103 | make build-tunnel |
| 104 | mkdir -p release |
| 105 | cp cmd/relay-server/dist/tunnel/portal-* release/ |
| 106 | cp cmd/portal-tunnel/installer/install.sh release/install.sh |
| 107 | cp cmd/portal-tunnel/installer/install.ps1 release/install.ps1 |
| 108 | |
| 109 | - name: Generate SHA256 checksums |
| 110 | shell: bash |
| 111 | run: | |
| 112 | cd release |
| 113 | sha256sum portal-* > checksums.txt |
| 114 | while read -r sum file; do |
| 115 | printf '%s %s\n' "$sum" "$file" > "${file}.sha256" |
| 116 | done < checksums.txt |
| 117 | |
| 118 | - name: Publish GitHub release assets |
| 119 | env: |
| 120 | GH_TOKEN: ${{ github.token }} |
| 121 | shell: bash |
| 122 | run: | |
| 123 | if gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1; then |
| 124 | gh release upload "${GITHUB_REF_NAME}" release/* --clobber |
| 125 | else |
| 126 | gh release create "${GITHUB_REF_NAME}" release/* \ |
| 127 | --generate-notes \ |
| 128 | --title "${GITHUB_REF_NAME}" |
| 129 | fi |