Skip to content

Commit

Permalink
Deploy from workflow (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrod-lowe authored Aug 25, 2024
1 parent 65f2204 commit 3dae0c4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/environment-main-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Compile, check and test graphql
run: IN_PIPELINE=true make graphql

- name: Test ui
run: IN_PIPELINE=true make ui-test

- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@a38818475bb21847788496e9f0fddaa4e84955ba
with:
Expand All @@ -47,6 +50,7 @@ jobs:

- name: terraform apply
uses: dflook/terraform-apply@7d435d4d115a11e5db1e710ac969f5382f0f6f9f
id: terraform
with:
path: terraform/environment/wildsea
variables: |
Expand All @@ -56,3 +60,23 @@ jobs:
bucket=${{ vars.STATE_BUCKET }}
key=${{ vars.ENVIRONMENT }}/terraform.tfstate
region=${{ vars.AWS_REGION }}

- name: write UI config file
run: |
cat > ui/config/output-${{ vars.ENVIRONMENT }}.json <<EOF
{
"ui_bucket": {"value": "${{ steps.terraform.outputs.ui_bucket }}"},
"cdn_id": {"value": "${{ steps.terraform.outputs.cdn_id }}"},
"cognito_identity_pool_id": {"value": ""},
"cognito_user_pool_id": {"value": ""},
"cognito_web_client_id": {"value": ""},
"graphql_uri": {"value": ""},
"region": {"value": ""},
"cognito_login_domain": {"value": ""},
"cdn_domain_name": {"value": ""},
}
EOF
- name: Push UI
run: |
IN_PIPELINE=true make ui/.push-${{ vars.ENVIRONMENT }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ ui/public/*
ui/dist/*
!ui/dist/.emptyDir
ui/.push
ui/.push-*
ui/coverage
ui/.build-*
1 change: 1 addition & 0 deletions terraform/environment/wildsea/output.tf
8 changes: 4 additions & 4 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions ui/ui.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ UI_JQ_FILTER := { \
loginDomain: .cognito_login_domain.value \
}

ifndef IN_PIPELINE
ui/config/output-%.json: terraform/environment/wildsea-%/.apply
cd $(dir $^) ; terraform output -json | tee ../../../$@
endif

ui/config/config-%.json: ui/config/output-%.json
jq "$(UI_JQ_FILTER)" $< >$@
Expand All @@ -21,11 +23,18 @@ ui-local: ui/config/config-dev.json appsync/schema.ts appsync/graphql.ts terrafo
ui/node_modules: ui/package.json
cd ui ; npm install

ui/dist/index.html: ui/config/config-dev.json appsync/schema.ts appsync/graphql.ts terraform/environment/wildsea-dev/.apply ui/src/*.ts ui/src/amplifyconfiguration.json ui/index.html ui/node_modules
cp $< ui/public/config.json
docker run --rm -it --user $$(id -u):$$(id -g) -v $(PWD):/app -w /app/ui --network host node:20 npm run build
ui/.build-%: appsync/schema.ts appsync/graphql.ts ui/src/*.ts ui/src/amplifyconfiguration.json ui/index.html ui/node_modules
cp ui/config/config-$*.json ui/public/config.json
if [ -z "$(IN_PIPELINE)" ] ; then \
docker run --rm -it --user $$(id -u):$$(id -g) -v $(PWD):/app -w /app/ui --network host node:20 npm run build ; \
else \
cd ui ; npm run build ; \
fi
touch $@

ui/.push: ui-test ui/.push-dev

ui/.push: ui/config/output-dev.json ui/dist/index.html ui-test
ui/.push-%: ui/config/output-%.json ui/config/config-%.json ui/.build-%
aws --no-cli-pager s3 sync ui/dist "s3://$$(jq -r .ui_bucket.value $< )"
aws --no-cli-pager s3 sync --delete ui/dist "s3://$$(jq -r .ui_bucket.value $< )"
aws --no-cli-pager cloudfront create-invalidation --distribution-id "$$(jq -r .cdn_id.value $<)" --paths '/*'
Expand All @@ -38,4 +47,3 @@ ui-test: ui/node_modules
else \
cd ui && ./node_modules/.bin/jest --coverage ; \
fi

0 comments on commit 3dae0c4

Please sign in to comment.