Merge pull request #1897 from microbiomedata/issue-1776-schema-json-i… #917
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| env: | |
| # We don't want to do certain steps if this is running in a fork | |
| IS_ORIGINAL_REPO: ${{ github.repository == 'microbiomedata/nmdc-server' }} | |
| # Used to determine if we add the special `prod` Docker image tag | |
| IS_PROD_RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| image: [server, client] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| # history for all branches and tags is needed for setuptools-scm | |
| fetch-depth: 0 | |
| # Generate tags and labels for the Docker container images. | |
| # | |
| # Note: The `type=sha,format=long` line makes it so every image is tagged with the Git commit hash. | |
| # We do this so people can reference (i.e. pin) a specific image version, even ones not tagged | |
| # with a version number via the `type=semver,pattern={{version}}` line. (The other tags may | |
| # refer to different image versions over time, so they cannot be used for this purpose.) | |
| # | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ghcr.io/microbiomedata/nmdc-server/${{ matrix.image }} | |
| flavor: | | |
| latest=false | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=raw,value=prod,enable=${{ env.IS_PROD_RELEASE }} | |
| type=sha,format=long | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ matrix.image == 'client' && 'web' || '.' }} | |
| push: ${{ env.IS_ORIGINAL_REPO }} | |
| file: ${{ matrix.image == 'client' && 'web/Dockerfile' || 'Dockerfile' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # Specify `--build-args` for the underlying `$ docker build` command. | |
| # | |
| # If the image being built is the one named "client", then set the "build argument" | |
| # named `VUE_APP_NMDC_GOOGLE_ANALYTICS_ID` to either the production or development | |
| # Google Analytics "Measurement ID" value, depending upon the `IS_PROD_RELEASE` | |
| # environment variable. Those GA "Measurement ID" values are stored in | |
| # repository-level variables, which are accessible via `vars.*`. | |
| # | |
| # References: | |
| # - https://github.com/docker/build-push-action/blob/master/README.md#inputs (RE: "build-args") | |
| # - https://docs.github.com/en/actions/reference/workflows-and-actions/expressions#format (RE: "format") | |
| # - https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-variables#using-contexts-to-access-variable-values (RE: "vars") | |
| # | |
| build-args: | | |
| ${{ | |
| matrix.image == 'client' && | |
| format( | |
| 'VUE_APP_NMDC_GOOGLE_ANALYTICS_ID={0}', | |
| env.IS_PROD_RELEASE == 'true' && vars.GOOGLE_ANALYTICS_ID_PROD || | |
| vars.GOOGLE_ANALYTICS_ID_DEV | |
| ) | |
| }} | |
| # Use the Rancher API to redeploy the specified deployments, | |
| # causing them to use the newly-pushed container images. | |
| redeploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| env: | |
| WORKLOAD_API_BASE: https://rancher2.spin.nersc.gov/v3/project/c-tmq7p:p-bkv45/workloads | |
| strategy: | |
| matrix: | |
| deployment: [ backend, frontend ] | |
| steps: | |
| - name: Redeploy nmdc-dev:portal-${{ matrix.deployment }} | |
| if: ${{ env.IS_PROD_RELEASE == 'false' && env.IS_ORIGINAL_REPO == 'true' }} | |
| uses: fjogeleit/http-request-action@v1 | |
| with: | |
| url: ${{ env.WORKLOAD_API_BASE }}/deployment:nmdc-dev:portal-${{ matrix.deployment }}?action=redeploy | |
| method: POST | |
| username: ${{ secrets.SPIN_USER }} | |
| password: ${{ secrets.SPIN_PASSWORD }} | |
| - name: Redeploy nmdc:portal-${{ matrix.deployment }} | |
| if: ${{ env.IS_PROD_RELEASE == 'true' && env.IS_ORIGINAL_REPO == 'true' }} | |
| uses: fjogeleit/http-request-action@v1 | |
| with: | |
| url: ${{ env.WORKLOAD_API_BASE }}/deployment:nmdc:portal-${{ matrix.deployment }}?action=redeploy | |
| method: POST | |
| username: ${{ secrets.SPIN_USER }} | |
| password: ${{ secrets.SPIN_PASSWORD }} |