-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): add test docker caching layer (#81)
Co-authored-by: muhammad-asghar-ali <[email protected]> Co-authored-by: Yousuf Jawwad <[email protected]>
- Loading branch information
1 parent
2f1cbef
commit d8a002c
Showing
2 changed files
with
82 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,31 +16,44 @@ env: | |
GCR_SERVICE: quantm-api-live-v1 | ||
|
||
jobs: | ||
release-artifact: | ||
build: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-20.04 | ||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
contents: 'read' | ||
id-token: 'write' | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set variables | ||
id: vars | ||
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
||
- name: Set up QEMU (for cross-compilation support) | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Go Build Cache for Docker | ||
uses: actions/cache@v4 | ||
with: | ||
path: go-build-cache | ||
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} | ||
|
||
- name: Authenticate with GCP | ||
id: auth | ||
uses: "google-github-actions/auth@v1" | ||
uses: 'google-github-actions/auth@v2' | ||
with: | ||
token_format: access_token | ||
credentials_json: ${{ secrets.GCP_JSON_KEY }} | ||
access_token_lifetime: 600s | ||
|
||
- name: Login into Google Artifact Registry | ||
uses: docker/login-action@v1 | ||
id: auth-gcp-artifact-registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.GCP_ARTIFACT_REPOSITORY }} | ||
username: oauth2accesstoken | ||
|
@@ -52,48 +65,73 @@ jobs: | |
cluster_name: ${{ env.GKE_CLUSTER }} | ||
location: ${{ env.GKE_CLUSTER_ZONE }} | ||
|
||
- name: Build & Push docker image for API | ||
run: | | ||
docker build --target api -t quantm/api:latest . | ||
docker tag quantm/api:latest ${{ env.GCP_ARTIFACT_REPOSITORY }}/api:latest | ||
docker tag quantm/api:latest ${{ env.GCP_ARTIFACT_REPOSITORY }}/api:${{ steps.vars.outputs.short_sha }} | ||
docker push ${{ env.GCP_ARTIFACT_REPOSITORY }}/api:latest | ||
docker push ${{ env.GCP_ARTIFACT_REPOSITORY }}/api:${{ steps.vars.outputs.short_sha }} | ||
- name: Inject go-build-cache into Docker | ||
# v1 was composed of two actions: "inject" and "extract". | ||
# v2 is unified to a single action. | ||
uses: reproducible-containers/[email protected] | ||
with: | ||
cache-source: go-build-cache | ||
|
||
- name: Build & Push docker image for migrate | ||
run: | | ||
docker build --target migrate -t quantm/migrate:latest . | ||
docker tag quantm/migrate:latest ${{ env.GCP_ARTIFACT_REPOSITORY }}/migrate:latest | ||
docker tag quantm/migrate:latest ${{ env.GCP_ARTIFACT_REPOSITORY }}/migrate:${{ steps.vars.outputs.short_sha }} | ||
docker push ${{ env.GCP_ARTIFACT_REPOSITORY }}/migrate:latest | ||
docker push ${{ env.GCP_ARTIFACT_REPOSITORY }}/migrate:${{ steps.vars.outputs.short_sha }} | ||
- name: Build & Push Docker Image - API | ||
id: build-api | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
target: api | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
push: true | ||
tags: | | ||
${{ env.GCP_ARTIFACT_REPOSITORY }}/api:latest | ||
${{ env.GCP_ARTIFACT_REPOSITORY }}/api:${{ steps.vars.outputs.short_sha }} | ||
- name: Build & Push docker image for mothership | ||
run: | | ||
docker build --target mothership -t quantm/mothership:latest . | ||
docker tag quantm/mothership:latest ${{ env.GCP_ARTIFACT_REPOSITORY }}/mothership:latest | ||
docker tag quantm/mothership:latest ${{ env.GCP_ARTIFACT_REPOSITORY }}/mothership:${{ steps.vars.outputs.short_sha }} | ||
docker push ${{ env.GCP_ARTIFACT_REPOSITORY }}/mothership:latest | ||
docker push ${{ env.GCP_ARTIFACT_REPOSITORY }}/mothership:${{ steps.vars.outputs.short_sha }} | ||
- name: Build & Push Docker Image - Mothership | ||
id: build-mothership | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
target: mothership | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
push: true | ||
tags: | | ||
${{ env.GCP_ARTIFACT_REPOSITORY }}/mothership:latest | ||
${{ env.GCP_ARTIFACT_REPOSITORY }}/mothership:${{ steps.vars.outputs.short_sha }} | ||
- name: Build & Push Docker Image - Migrate | ||
id: build-migrate | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
target: migrate | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
push: true | ||
tags: | | ||
${{ env.GCP_ARTIFACT_REPOSITORY }}/migrate:latest | ||
${{ env.GCP_ARTIFACT_REPOSITORY }}/migrate:${{ steps.vars.outputs.short_sha }} | ||
- name: Get deployments | ||
- name: Get Quantm Deployments in GKE | ||
id: get-gke-deployments | ||
run: | | ||
kubectl get -n quantm deploy | ||
- name: Deploy mothership docker image to the GKE cluster | ||
id: deploy-mothership | ||
run: | | ||
kubectl patch -n quantm deployment mothership -p \ | ||
'{"spec":{"template":{"spec":{"containers":[{"name":"mothership","image":"us-docker.pkg.dev/quantm-live/default-live-v1/mothership:${{ steps.vars.outputs.short_sha }}"}]}}}}' | ||
- name: Deploy API to Cloud Run | ||
id: deployAPI | ||
id: deploy-api | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
service: ${{ env.GCR_SERVICE }} | ||
image: ${{ env.GCP_ARTIFACT_REPOSITORY }}/api:${{ steps.vars.outputs.short_sha }} | ||
|
||
- name: Use output | ||
run: curl ${{ steps.deployAPI.outputs.url }} | ||
- name: Healthcheck for API | ||
id: healthcheck-api | ||
run: curl ${{ steps.deploy-api.outputs.url }} | ||
|
||
- name: docker ls | ||
run: docker image ls |
This file contains 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