|
| 1 | +run-name: Build push and deploy (CD) |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + tags: |
| 7 | + - '*' |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-and-push-to-gcr: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + concurrency: |
| 13 | + group: ${{ github.ref_type == 'branch' && github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + outputs: |
| 18 | + image-name: ${{ steps.set-image-name.outputs.image_name }} |
| 19 | + release-version: ${{ steps.set-image-name.outputs.release_version }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + - uses: 'google-github-actions/auth@v2' |
| 23 | + with: |
| 24 | + credentials_json: '${{ secrets.GCLOUD_SERVICE_ACCOUNT_SECRET_JSON }}' |
| 25 | + - name: 'Set up Cloud SDK' |
| 26 | + uses: 'google-github-actions/setup-gcloud@v2' |
| 27 | + with: |
| 28 | + install_components: beta |
| 29 | + - name: "Docker auth" |
| 30 | + run: |- |
| 31 | + gcloud auth configure-docker asia-southeast1-docker.pkg.dev --quiet |
| 32 | + - name: Set controller release version |
| 33 | + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV |
| 34 | + - name: Set up Node.js |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: 24.14.0 |
| 38 | + cache: npm |
| 39 | + |
| 40 | + - name: npm install |
| 41 | + run: npm ci |
| 42 | + - name: build application |
| 43 | + run: npm run build |
| 44 | + - name: npm install fe |
| 45 | + run: npm ci |
| 46 | + working-directory: fe |
| 47 | + - name: build fe |
| 48 | + run: npm run build |
| 49 | + working-directory: fe |
| 50 | + - name: Set package version |
| 51 | + run: npm version --no-git-tag-version ${{ env.RELEASE_VERSION }} |
| 52 | + if: github.ref_type == 'tag' |
| 53 | + - name: Docker meta |
| 54 | + id: meta |
| 55 | + uses: docker/metadata-action@v5 |
| 56 | + with: |
| 57 | + images: | |
| 58 | + asia-southeast1-docker.pkg.dev/elastic-ml/jina-demo/wikipedia-vector-demo |
| 59 | + - name: Set up QEMU |
| 60 | + uses: docker/setup-qemu-action@v3 |
| 61 | + - name: Set up Docker Buildx |
| 62 | + uses: docker/setup-buildx-action@v3 |
| 63 | + - name: Build and push |
| 64 | + id: container |
| 65 | + uses: docker/build-push-action@v6 |
| 66 | + with: |
| 67 | + context: . |
| 68 | + push: true |
| 69 | + tags: ${{ steps.meta.outputs.tags }} |
| 70 | + labels: ${{ steps.meta.outputs.labels }} |
| 71 | + - name: Set image name |
| 72 | + id: set-image-name |
| 73 | + run: | |
| 74 | + echo "image_name=asia-southeast1-docker.pkg.dev/elastic-ml/jina-demo/wikipedia-vector-demo@${{steps.container.outputs.imageid}}" >> $GITHUB_OUTPUT |
| 75 | + echo "release_version=${{ env.RELEASE_VERSION }}" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + deploy-services: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: build-and-push-to-gcr |
| 80 | + if: github.ref_name != 'ops' |
| 81 | + strategy: |
| 82 | + matrix: |
| 83 | + region: [asia-southeast1] |
| 84 | + steps: |
| 85 | + - uses: 'google-github-actions/auth@v2' |
| 86 | + with: |
| 87 | + credentials_json: '${{ secrets.GCLOUD_SERVICE_ACCOUNT_SECRET_JSON }}' |
| 88 | + - name: 'Set up Cloud SDK' |
| 89 | + uses: 'google-github-actions/setup-gcloud@v2' |
| 90 | + with: |
| 91 | + install_components: beta |
| 92 | + - name: Deploy Demo Server with Tag (${{ matrix.region }}) |
| 93 | + run: | |
| 94 | + gcloud beta run deploy wikipedia-vector-demo --image ${{ needs.build-and-push-to-gcr.outputs.image-name }} --tag ${{ needs.build-and-push-to-gcr.outputs.release-version }} --command '' --args build/server.js --region ${{ matrix.region }} --async --min-instances 0 --deploy-health-check --use-http2 |
0 commit comments