Skip to content

Commit

Permalink
Merge pull request #78 from lsst-epo/develop
Browse files Browse the repository at this point in the history
chore(release
  • Loading branch information
jrosati-burwood authored Feb 5, 2025
2 parents 215e4aa + 70230f2 commit 11534af
Show file tree
Hide file tree
Showing 69 changed files with 4,457 additions and 2,157 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: Build, Push, and Deploy

on:
push:
branches:
- 'develop'
- 'main'
tags:
- 'v*'
pull_request:
types:
- labeled
- 'opened'
- 'synchronize'
- 'reopened'
branches:
- 'develop'
- 'main'

jobs:
build:
if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'preview') || github.event.label.name == 'preview' }}
name: Build Container Image
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.deploy-tag.outputs.image_tag }}
image_name: ${{ steps.deploy-tag.outputs.image_name }}
environment_name: ${{ steps.deploy-info.outputs.environment_name }}
steps:
-
name: Checkout
uses: actions/[email protected]
-
name: Parse deployment info
id: deploy-info
run: |
# Determine environment to deploy to
if ${{ github.ref_type == 'tag'}}; then
environment_name="prod"
credentials_json='${{ secrets.PIPELINE_EPO_PROD_PROJECT }}'
elif ${{ contains(github.ref_name, 'main') || contains(github.base_ref, 'main') }}; then
environment_name="int"
credentials_json='${{ secrets.SKYVIEWER_INT_SERVICE_ACCOUNT }}'
else
environment_name="dev"
credentials_json='${{ secrets.DEV_SA_KEY }}'
fi
echo environment_name=$environment_name >> "$GITHUB_OUTPUT"
echo credentials_json=$credentials_json >> "$GITHUB_OUTPUT"
-
name: Docker meta
id: meta
uses: docker/[email protected]
with:
# list of Docker images to use as base name for tags
images: |
gcr.io/skyviewer/skyviewer-api-k8s,enable=${{ steps.deploy-info.outputs.environment_name == 'dev' }}
gcr.io/edc-int-6c5e/skyviewer-api-k8s,enable=${{ steps.deploy-info.outputs.environment_name == 'int' }}
gcr.io/edc-prod-eef0/skyviewer-api-k8s,enable=${{ steps.deploy-info.outputs.environment_name == 'prod' }}
flavor: |
latest=${{ github.event_name == 'push'}}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Parse deploy tag
id: deploy-tag
run: |
# Parse container image tag to deploy
full_tag=$(echo "$DOCKER_METADATA_OUTPUT_JSON" | jq -r '.tags[0]')
echo "Will use tag \"$full_tag\" for deployment."
echo image_tag=$(echo "$full_tag" | cut -f2 -d:) >> "$GITHUB_OUTPUT"
echo image_name=$(echo "$full_tag" | cut -f1 -d:) >> "$GITHUB_OUTPUT"
echo full_tag=$full_tag >> "$GITHUB_OUTPUT"
-
name: Set up QEMU
uses: docker/[email protected]
-
name: Set up Docker Buildx
uses: docker/[email protected]
-
name: Login to GCP
uses: 'google-github-actions/[email protected]'
with:
credentials_json: ${{ steps.deploy-info.outputs.credentials_json }}
-
name: 'Set up Cloud SDK'
uses: 'google-github-actions/[email protected]'
-
run: gcloud --quiet auth configure-docker
-
name: Build and push
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-to: |
type=gha
cache-from: |
type=gha
build-args: |
BASE_TAG=k8s
-
uses: imjasonh/[email protected]
if: ${{ github.event_name == 'pull_request' }}
-
name: Preview prep
if: ${{ github.event_name == 'pull_request' }}
run: |-
CLIENT_IMAGE=$(echo "${{ steps.deploy-tag.outputs.image_name }}" | sed -e 's/-api/-client/g')
if ! crane config ${CLIENT_IMAGE}:${{ steps.deploy-tag.outputs.image_tag }}; then
crane tag ${CLIENT_IMAGE}:latest ${{ steps.deploy-tag.outputs.image_tag }}
fi
-
name: Summary
run: |
cat <<-EOT >> "$GITHUB_STEP_SUMMARY"
# Container Build Completed
## Tags
${{ steps.meta.outputs.tags }}
EOT
deploy:
name: Trigger deploy to ${{ needs.build.outputs.environment_name }}
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' }}
steps:
- name: Generate Webhook Payload
id: payload
run: |-
PARAMETERS=(
api.image.tag=${{ needs.build.outputs.image_tag }}
api.image.repository=${{ needs.build.outputs.image_name }}
)
DATA="{
\"app_name\": \"skyviewer\",
\"environment_name\": \"${{ needs.build.outputs.environment_name }}\",
\"parameters\": $(jq -c -n '$ARGS.positional' --args ${PARAMETERS[@]})
}"
echo "data=$(echo $DATA | jq -rc '.')" >> "$GITHUB_OUTPUT"
- uses: lasith-kg/[email protected]
id: dispatch
name: Trigger Deployment
with:
dispatch-method: repository_dispatch
repo: edc-deploy
owner: lsst-epo
event-type: app_update_values
token: ${{ secrets.EDC_DEPLOY_GITHUB_TOKEN_FOR_REST_API }}
workflow-inputs: ${{ steps.payload.outputs.data }}
discover: true
- name: Await Run ID ${{ steps.dispatch.outputs.run-id }}
uses: Codex-/[email protected]
with:
token: ${{ secrets.EDC_DEPLOY_GITHUB_TOKEN_FOR_REST_API }}
repo: edc-deploy
owner: lsst-epo
run_id: ${{ steps.dispatch.outputs.run-id }}
run_timeout_seconds: 1500

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ app.yaml
# DB stuff
/db/*.sql
!/db/Dockerfile
docker-compose-local-db.yml
docker-compose-local-db.yml
api/supervisor.log
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
dev:
docker-compose -f docker-compose-local-db.yml up --build

clean:
docker system prune -f && docker volume prune -f

clean-images:
docker images prune

# Requires argument `dbname` to specify the name of the new DB, usage: `make local-db dbname=my_db dbfile=mydb.sql`
# Requires argument `dbfile` to specify the name of the DB dump file to recreate, usage: `make local-db dbname=my_db dbfile=mydb.sql`
local-db:
cd db && docker exec --workdir / skyviewer-api-postgres-1 psql -U skyviewer -c "create database $(dbname);"
cd db && docker exec --workdir / skyviewer-api-postgres-1 psql -U skyviewer -d $(dbname) -f $(dbfile)
echo "\n\n\n\nDon't forget to update your docker-compose-local-db.yaml with the DB name: $(dbname)"

db-list:
cd db && docker exec --workdir / skyviewer-api-postgres-1 psql -U skyviewer -c "SELECT (pg_stat_file('base/'||oid ||'/PG_VERSION')).modification, datname FROM pg_database;"

cloud-db-list:
curl https://us-central1-edc-prod-eef0.cloudfunctions.net/sql-helper/databases\?project\=skyviewer

# Requires argument `dbname` to specify the name of the DB to be exported, usage: `make cloud-db-export dbname=prod_db`
cloud-db-export:
curl --header "Content-Type: application/json" \
--request POST \
--data '{"project":"skyviewer"}' \
https://us-central1-edc-prod-eef0.cloudfunctions.net/sql-helper/databases\?action\=export\&database\=$(dbname)
21 changes: 13 additions & 8 deletions api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/lsst-epo/craft3-nested-entries-graphql-queries.git"
"url": "https://github.com/lsst-epo/craft-next-js-builds.git"
},
{
"type": "vcs",
"url": "https://github.com/lsst-epo/craft3-universal-dam-integrator.git"
"url": "https://github.com/lsst-epo/canto-dam-assets.git"
},
{
"type": "composer",
"url": "https://composer.craftcms.com",
"canonical": false
}
],
"require": {
"craftcms/cms": "3.7.17.1",
"craftcms/google-cloud": "^1.4",
"craftcms/redactor": "2.8.8",
"craftcms/cms": "^4.0.0",
"craftcms/google-cloud": "2.1.0",
"craftcms/redactor": "3.0.4",
"google/cloud-storage": "^1.24",
"rosas/nested-entries-graphql-queries": "^1.0",
"rosas/universal-dam-integrator": "dev-main",
"lsst-epo/canto-dam-assets": "^4.3",
"lsst-epo/craft-next-js-builds": "2.0.1",
"vlucas/phpdotenv": "^3.4.0",
"yiisoft/yii2-redis": "^2.0"
},
Expand All @@ -34,7 +39,7 @@
"sort-packages": true,
"optimize-autoloader": true,
"platform": {
"php": "7.2.5"
"php": "8.1.10"
},
"allow-plugins": {
"yiisoft/yii2-composer": true,
Expand Down
Loading

0 comments on commit 11534af

Please sign in to comment.