|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + paths-ignore: [ '**.md','docker-compose.yml' ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-web: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Setup Node.js |
| 17 | + uses: actions/setup-node@v4 |
| 18 | + with: |
| 19 | + node-version: '22' |
| 20 | + cache: 'npm' |
| 21 | + cache-dependency-path: web/package-lock.json |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + working-directory: web |
| 25 | + run: npm ci |
| 26 | + |
| 27 | + - name: Build web |
| 28 | + working-directory: web |
| 29 | + run: npm run build |
| 30 | + |
| 31 | + - name: Upload web artifact |
| 32 | + uses: actions/upload-artifact@v4 |
| 33 | + with: |
| 34 | + name: web-out |
| 35 | + path: web/out |
| 36 | + |
| 37 | + build-backend: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + strategy: |
| 40 | + matrix: |
| 41 | + arch: [amd64, arm64] |
| 42 | + include: |
| 43 | + - arch: amd64 |
| 44 | + goarch: amd64 |
| 45 | + - arch: arm64 |
| 46 | + goarch: arm64 |
| 47 | + steps: |
| 48 | + - name: Checkout repository |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up Go |
| 52 | + uses: actions/setup-go@v5 |
| 53 | + with: |
| 54 | + go-version: '1.23' |
| 55 | + |
| 56 | + - name: Build binary |
| 57 | + env: |
| 58 | + GOOS: linux |
| 59 | + GOARCH: ${{ matrix.goarch }} |
| 60 | + CGO_ENABLED: 0 |
| 61 | + run: | |
| 62 | + go build -o proxy-go-${{ matrix.arch }} |
| 63 | +
|
| 64 | + - name: Upload binary artifact |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: proxy-go-${{ matrix.arch }} |
| 68 | + path: proxy-go-${{ matrix.arch }} |
| 69 | + |
| 70 | + docker: |
| 71 | + needs: [build-web, build-backend] |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - name: Checkout repository |
| 75 | + uses: actions/checkout@v4 |
| 76 | + |
| 77 | + - name: Download all artifacts |
| 78 | + uses: actions/download-artifact@v4 |
| 79 | + |
| 80 | + - name: Set up QEMU |
| 81 | + uses: docker/setup-qemu-action@v3 |
| 82 | + |
| 83 | + - name: Set up Docker Buildx |
| 84 | + uses: docker/setup-buildx-action@v3 |
| 85 | + |
| 86 | + - name: Login to Docker Hub |
| 87 | + uses: docker/login-action@v3 |
| 88 | + with: |
| 89 | + username: woodchen |
| 90 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 91 | + |
| 92 | + - name: Create Docker build context |
| 93 | + run: | |
| 94 | + mkdir -p docker-context |
| 95 | + cp Dockerfile docker-context/ |
| 96 | + cp proxy-go-amd64/proxy-go-amd64 docker-context/proxy-go.amd64 |
| 97 | + cp proxy-go-arm64/proxy-go-arm64 docker-context/proxy-go.arm64 |
| 98 | + mkdir -p docker-context/web/out |
| 99 | + cp -r web-out/* docker-context/web/out/ |
| 100 | + |
| 101 | + - name: Build and push Docker images |
| 102 | + uses: docker/build-push-action@v6 |
| 103 | + with: |
| 104 | + context: docker-context |
| 105 | + platforms: linux/amd64,linux/arm64 |
| 106 | + push: true |
| 107 | + tags: | |
| 108 | + woodchen/proxy-go:${{ github.ref_name }} |
| 109 | + woodchen/proxy-go:stable |
0 commit comments