Skip to content

Commit

Permalink
Separate dev and production deployments in GitHub workflow (#382)
Browse files Browse the repository at this point in the history
* Consolidate workflows for building docker images and deploying to Spin into one workflow

* Remove docker-build.sh in favor of letting GitHub Actions handle Docker build and push

* Update Release Process doc with info about initiating via GitHub Releases

* Replace Rancher-Action with generic HTTP call

* Replace release event with tag push event, which is required for semver metadata

* Remove unnecessary pr event

* Add more release instructions
  • Loading branch information
pkalita-lbl authored Nov 20, 2023
1 parent d3c0e0d commit acbc9f9
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 192 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.idea
docker-compose.yml
.dockerignore
docker-build.sh
deployment
.eggs
.pytest_cache
Expand Down
45 changes: 0 additions & 45 deletions .github/workflows/build-and-push-docker-images.yml

This file was deleted.

81 changes: 81 additions & 0 deletions .github/workflows/build-and-release-to-spin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build Docker images and release to Spin

on:
push:
branches:
- main
tags:
- 'v*'
paths:
- '.github/workflows/build-and-release-to-spin.yml'
- 'Makefile'
- '**.Dockerfile'
- '**.py'
- 'requirements/main.txt'

env:
IS_PROD_RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }}

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
image: [ fastapi, dagster ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
microbiomedata/nmdc-runtime-${{ matrix.image }}
flavor: |
latest=false
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=raw,value=prod,enable=${{ env.IS_PROD_RELEASE }}
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
file: nmdc_runtime/${{ matrix.image }}.Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

release:
needs: build

runs-on: ubuntu-latest

strategy:
matrix:
deployment: [ runtime-api, dagster-dagit, dagster-daemon ]

env:
NAMESPACE: ${{ env.IS_PROD_RELEASE && 'nmdc' || 'nmdc-dev' }}

steps:
- name: Redeploy ${{ env.NAMESPACE }}:${{ matrix.deployment }}
uses: fjogeleit/http-request-action@v1
with:
url: ${{ secrets.RANCHER_URL }}/v3/project/${{ secrets.RANCHER_CONTEXT }}/workloads/deployment:${{ env.NAMESPACE }}:${{ matrix.deployment }}?action=redeploy
method: POST
bearerToken: ${{ secrets.RANCHER_TOKEN }}
55 changes: 0 additions & 55 deletions .github/workflows/release-to-spin.yml

This file was deleted.

8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,9 @@ down-test:
follow-fastapi:
docker-compose logs fastapi -f

fastapi-docker:
./docker-build.sh microbiomedata/nmdc-runtime-fastapi nmdc_runtime/fastapi.Dockerfile

fastapi-deploy-spin:
rancher kubectl rollout restart deployment/runtime-fastapi --namespace=nmdc-dev

dagster-docker:
./docker-build.sh microbiomedata/nmdc-runtime-dagster nmdc_runtime/dagster.Dockerfile

dagster-deploy-spin:
rancher kubectl rollout restart deployment/dagit --namespace=nmdc-dev
rancher kubectl rollout restart deployment/dagster-daemon --namespace=nmdc-dev
Expand Down Expand Up @@ -99,4 +93,4 @@ quick-blade:
python -c "from nmdc_runtime.api.core.idgen import generate_id; print(f'nmdc:nt-11-{generate_id(length=8, split_every=0)}')"

.PHONY: init update-deps update up-dev down-dev follow-fastapi \
fastapi-docker dagster-docker publish docs
publish docs
78 changes: 0 additions & 78 deletions docker-build.sh

This file was deleted.

16 changes: 10 additions & 6 deletions docs/howto-guides/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ released? Here's how.
[our python-app.yml GitHub
action](https://github.com/microbiomedata/nmdc-runtime/blob/main/.github/workflows/python-app.yml),
which is triggered automatically when a change to any Python file in the repository is pushed to the
`main` branch, or to a Pull Request. You can monitor the status of Github Actions
`main` branch, or to a Pull Request. You can monitor the status of GitHub Actions
[here](https://github.com/microbiomedata/nmdc-runtime/actions).

2. Add a summary for the release to `RELEASES.md`. You can make an edit and push to the `main`
branch [via GitHub](https://github.com/microbiomedata/nmdc-runtime/blob/main/RELEASES.md). This will
trigger two GitHub actions in sequence to
2. Create a new [GitHub Release](https://github.com/microbiomedata/nmdc-runtime/releases). When creating the new release:
- Use the "Choose a tag" dropdown to **create a new tag** by typing in a tag name which does not exist yet.
- The new tag name should start with `v` and be followed by a [semantic version number](https://semver.org/), for example `v3.0.2`.
- If the last published version is `vX.Y.Z`, the next release number should be `vX.Y.{Z+1}` for a patch release (bux fixes and refactoring), `vX.{Y+1}.0` for a minor release (new functionality that is backwards-compatible), or `v{X+1}.0.0` for a major release (new functionality that may be backwards-incompatible).
- You may leave the "Release title" input blank. If it is blank the release title will be populated with the tag name.

- [build and push updated Docker images](https://github.com/microbiomedata/nmdc-runtime/blob/main/.github/workflows/build-and-push-docker-images.yml) for the API server and for the NMDC Runtime site's Dagster daemon and Dagit dashboard, and
Once the GitHub Release has been created, two GitHub Actions will be triggered which:

- [deploy the new images to Spin](https://github.com/microbiomedata/nmdc-runtime/blob/main/.github/workflows/release-to-spin.yml).
- [build Docker images and deploy them to Spin](https://github.com/microbiomedata/nmdc-runtime/blob/main/.github/workflows/build-and-release-to-spin.yml) for the API server and for the NMDC Runtime site's Dagster daemon and Dagit dashboard.
- [build a Python package and publish it to PyPI](https://github.com/microbiomedata/nmdc-runtime/blob/main/.github/workflows/release-to-pypi.yml).
## Data Releases
Expand Down

0 comments on commit acbc9f9

Please sign in to comment.