Skip to content

Commit

Permalink
Refactor deploy workflows (#12)
Browse files Browse the repository at this point in the history
* formatting

* store deploy target as env variable in workflow (target is not secret)

* workflow badges in readme

* open links in new tab
  • Loading branch information
ntno authored Dec 28, 2022
1 parent bd07dc6 commit 2054084
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Simple workflow for deploying mkdocs site
name: Deploy MkDocs to Development Environment

env:
deploy-target: factually-settled-boxer-development
deployment-url: http://factually-settled-boxer-development.s3-website.us-east-1.amazonaws.com

on:
workflow_dispatch:
inputs:
Expand All @@ -16,7 +20,7 @@ on:
- dev
- prod
perform-deploy:
description: 'Enables deployment to factually-settled-boxer-dev'
description: 'Enable deployment to factually-settled-boxer-development'
required: true
type: boolean

Expand Down Expand Up @@ -65,7 +69,7 @@ jobs:
runs-on: ubuntu-latest
environment:
name: gh-dev
url: http://factually-settled-boxer-dev.s3-website.us-east-1.amazonaws.com
url: ${{ env.deployment-url }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -88,7 +92,7 @@ jobs:
with:
version: ${{ inputs.tag }}/${{ inputs.env-vars }}
env-name: ${{ inputs.env-vars }}
s3-bucket: ${{ secrets.DEPLOY_TARGET }}
s3-bucket: ${{ env.deploy-target }}
aws-region: us-east-1
make-vars-for-deploy-target: ${{ env.deploy-flags }}
role-to-assume: ${{ secrets.ROLE_ARN }}
Expand All @@ -98,6 +102,6 @@ jobs:
export MESSAGE="Deploy is disabled for current workflow run, deployment skipped..."
echo "::notice title=Deployment Skipped::$MESSAGE"
else
export MESSAGE="${{ inputs.tag }}/${{ inputs.env-vars }} deployed to ${{ jobs.deploy-mkdocs.environment.url }} with ${{ needs.call-metadata-workflow.outputs.build-tag }}"
export MESSAGE="${{ inputs.tag }}/${{ inputs.env-vars }} deployed to ${{ env.deployment-url }} with ${{ needs.call-metadata-workflow.outputs.build-tag }}"
echo "::notice title=Deployment Complete::$MESSAGE"
fi
12 changes: 8 additions & 4 deletions .github/workflows/prod-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Simple workflow for deploying mkdocs site
name: Deploy MkDocs to Production Environment

env:
deploy-target: factually-settled-boxer
deployment-url: http://factually-settled-boxer.s3-website.us-east-1.amazonaws.com

on:
workflow_dispatch:
inputs:
Expand All @@ -16,7 +20,7 @@ on:
- prod
- dev
perform-deploy:
description: 'Enables deployment to factually-settled-boxer'
description: 'Enable deployment to factually-settled-boxer'
required: true
type: boolean

Expand Down Expand Up @@ -65,7 +69,7 @@ jobs:
runs-on: ubuntu-latest
environment:
name: gh-prod
url: http://factually-settled-boxer.s3-website.us-east-1.amazonaws.com
url: ${{ env.deployment-url }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -88,7 +92,7 @@ jobs:
with:
version: ${{ inputs.tag }}/${{ inputs.env-vars }}
env-name: ${{ inputs.env-vars }}
s3-bucket: ${{ secrets.DEPLOY_TARGET }}
s3-bucket: ${{ env.deploy-target }}
aws-region: us-east-1
make-vars-for-deploy-target: ${{ env.deploy-flags }}
role-to-assume: ${{ secrets.ROLE_ARN }}
Expand All @@ -98,6 +102,6 @@ jobs:
export MESSAGE="Deploy is disabled for current workflow run, deployment skipped..."
echo "::notice title=Deployment Skipped::$MESSAGE"
else
export MESSAGE="${{ inputs.tag }}/${{ inputs.env-vars }} deployed to ${{ jobs.deploy-mkdocs.environment.url }} with ${{ needs.call-metadata-workflow.outputs.build-tag }}"
export MESSAGE="${{ inputs.tag }}/${{ inputs.env-vars }} deployed to ${{ env.deployment-url }} with ${{ needs.call-metadata-workflow.outputs.build-tag }}"
echo "::notice title=Deployment Complete::$MESSAGE"
fi
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ mkdocs demo site

## live environments
### integration
- temporary environments are created/destroyed with pull request open/close
- url is posted to the pull request for review

temporary environments are created/destroyed with pull request open/close

url: posted to the pull request for review
status:
[![Test Pull Request](https://github.com/ntno/mkdocs-demo/actions/workflows/test-pr.yml/badge.svg?event=pull_request)](https://github.com/ntno/mkdocs-demo/actions/workflows/test-pr.yml)

### development
url: [http://factually-settled-boxer-development.s3-website-us-east-1.amazonaws.com](http://factually-settled-boxer-development.s3-website-us-east-1.amazonaws.com)
deployment workflow: (todo)
url: [http://factually-settled-boxer-development.s3-website-us-east-1.amazonaws.com](http://factually-settled-boxer-development.s3-website-us-east-1.amazonaws.com){target="_blank"}
status:
[![Deploy MkDocs to Development Environment](https://github.com/ntno/mkdocs-demo/actions/workflows/dev-deploy.yml/badge.svg?branch=main)](https://github.com/ntno/mkdocs-demo/actions/workflows/dev-deploy.yml)

### production
url: [http://factually-settled-boxer.s3-website-us-east-1.amazonaws.com](http://factually-settled-boxer.s3-website-us-east-1.amazonaws.com)
deployment workflow: (todo)
url: [http://factually-settled-boxer.s3-website-us-east-1.amazonaws.com](http://factually-settled-boxer.s3-website-us-east-1.amazonaws.com){target="_blank"}
status:
[![Deploy MkDocs to Production Environment](https://github.com/ntno/mkdocs-demo/actions/workflows/prod-deploy.yml/badge.svg)](https://github.com/ntno/mkdocs-demo/actions/workflows/prod-deploy.yml)

## local development

Expand All @@ -28,14 +33,14 @@ ex: run server with ['prod/us-east-1'](variables.yml#L21-L25) site variables
## prerequisites
- install docker and Make (for local development)
- set up OIDC provider in AWS console
- [Use OpenID Connect within your workflows to authenticate with Amazon Web Services.](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)
- [Use OpenID Connect within your workflows to authenticate with Amazon Web Services.](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services){target="_blank"}
- create S3 bucket for static website hosting
- create supporting cicd resources (S3 bucket for site artifacts and IAM roles for GitHub Action workflows to assume)


### infrastructure (onetime setup)

see terraform code in [`infra/`](infra/) for example on how to create required resources. [`ntno/tf-module-static-site-cicd`](https://github.com/ntno/tf-module-static-site-cicd) is used to create CICD IAM roles and artifact bucket.
see terraform code in [`infra/`](infra/) for example on how to create required resources. [`ntno/tf-module-static-site-cicd`](https://github.com/ntno/tf-module-static-site-cicd){target="_blank"} is used to create CICD IAM roles and artifact bucket.

```
make ubuntu
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ this is **bold** text

this is _italics_

this site was deployed with `env={{ ENV_LEVEL }}` and `region={{ REGION }}` variables
this site was built with `env={{ ENV_LEVEL }}` and `region={{ REGION }}` variables

0 comments on commit 2054084

Please sign in to comment.