Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5320 devops cicd #21

Merged
merged 58 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
f82aa18
update .gitignore with tf/tg rules
digorgonzola Dec 19, 2023
a499384
add .pre-commit-config.yaml
digorgonzola Dec 19, 2023
c539073
formatting fixes for existing code
digorgonzola Dec 19, 2023
2863f18
initial commit for deployment code
digorgonzola Dec 19, 2023
0a8ee1d
init commit for github workflows
digorgonzola Dec 19, 2023
ed3752d
github env vars for dev: update env name to tf_development (temporarily)
digorgonzola Dec 19, 2023
a542c62
deploy-development.yml: allow workflow dispatch
digorgonzola Dec 19, 2023
77979cf
deploy-development.yml: temporary push event response
digorgonzola Dec 19, 2023
af7739c
github vars: update app_port to 8000
digorgonzola Dec 19, 2023
1dfc04c
deploy-development.yml: update environment
digorgonzola Dec 19, 2023
496fb27
add sample docker structure tests
digorgonzola Dec 19, 2023
0adea3d
deploy/tf: fix container health check
digorgonzola Dec 19, 2023
2e4176c
deploy-development.yml: export TF_VAR variables with correct case
digorgonzola Dec 19, 2023
323b39c
tf: update health-check
digorgonzola Dec 19, 2023
be7592c
deploy/github: update app port to 8080
digorgonzola Dec 19, 2023
c2f76f6
tg: prefer use of tfvars.json for variable overrides
digorgonzola Dec 19, 2023
d4aa672
tf/service: add health_check_path variable
digorgonzola Dec 19, 2023
b1b562e
github: remove TF_VAR from env file
digorgonzola Dec 19, 2023
a9de2c8
tf: support advanced health check parameters
digorgonzola Dec 19, 2023
dd8e86d
default.auto.tfvars.json: add further default vars
digorgonzola Dec 19, 2023
a7473ef
github: update development.env values
digorgonzola Dec 19, 2023
ca2c8e2
default.env: include additional variables
digorgonzola Dec 19, 2023
c1107b7
default.auto.tfvars.json: increase mem to 3GB
digorgonzola Dec 19, 2023
4a6747c
update container vars
digorgonzola Dec 19, 2023
5a1a838
tf: support passing secrets to container definition
digorgonzola Dec 20, 2023
aab72a9
tg: remove default.auto.tfvars.json
digorgonzola Dec 20, 2023
a1b5c23
tg: gather override vars + secrets from environment
digorgonzola Dec 20, 2023
2859b49
deploy: add in environment tf vars + secrets
digorgonzola Dec 20, 2023
633b760
deploy: add symlink to development (temporary workaround)
digorgonzola Dec 20, 2023
03be115
tf_vars: merge secrets in variables.yaml
digorgonzola Dec 20, 2023
db261ec
tf: update var name to container_secrets
digorgonzola Dec 20, 2023
2ffa230
tg: remove secrets (merged into vars)
digorgonzola Dec 20, 2023
8ffb4f8
major refactor to avoid the github variables mess
digorgonzola Dec 20, 2023
9da82b9
assign correct permissions to task_exec role for pulling s3 env files
digorgonzola Dec 20, 2023
00a7c23
update development.env variables
digorgonzola Dec 20, 2023
49a7d53
github workflows: add step to sync .env files to s3
digorgonzola Dec 20, 2023
e51c138
remove deployment from app repo
digorgonzola Dec 29, 2023
ab6b04a
.pre-commit-config.yaml: remove terraform checks
digorgonzola Jan 1, 2024
9f8c300
update github workflows
digorgonzola Jan 1, 2024
35a39eb
update pre-commit.yml: remove terragrunt/terraform
digorgonzola Jan 24, 2024
67da85f
github: add separate test workflow
digorgonzola Jan 24, 2024
76d2e78
github: refactor build jobs
digorgonzola Jan 24, 2024
53f9518
github builds: remove unncessary extra build
digorgonzola Jan 24, 2024
9486bb3
github: add .env files for environment variables
digorgonzola Jan 24, 2024
1226f58
add README.md for github variable .env files
digorgonzola Jan 24, 2024
693317a
test.yml: make docker build steps more generic
digorgonzola Jan 24, 2024
41c0557
test.yml: rename job to "build_test"
digorgonzola Jan 24, 2024
308d0f2
github: ignore changes to .md files
digorgonzola Jan 24, 2024
9536ee9
github: further paths to ignore
digorgonzola Jan 24, 2024
74e5b05
github: update workflows with deploy trigger
digorgonzola Feb 7, 2024
5192d40
maven: add git versioning extension
digorgonzola Feb 8, 2024
57b1442
maven: configure publishing to codeartifact
digorgonzola Feb 8, 2024
04bb165
github: add mvn deployment steps
digorgonzola Feb 8, 2024
eaf762d
github: configure settings.xml from java action
digorgonzola Feb 8, 2024
9ee900a
github/environment: update sample variables
digorgonzola Feb 8, 2024
f051fb9
github/workflows: remove unnecessary codeartifact username
digorgonzola Feb 8, 2024
19e10a4
github/workflows/staging: clean up steps ready for merging
digorgonzola Feb 8, 2024
13e0fe8
github/workflows/production: add required steps for release workflow
digorgonzola Feb 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Github Deployment Environments
Github deployment environments are used to define unique settings for each environment i.e. staging and production

The build and push workflows need to know which AWS account to push updated docker images to.

### DotEnv Files
The .env files in this directory are here as a record of the "variables" and their values.

The variables can be updated from these files using the following command:
```bash
gh variable set -R aodn/<repo name> -e <environment name> -f <environment>.env

```
5 changes: 5 additions & 0 deletions .github/environment/production.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AWS_REGION=ap-southeast-2
CODEARTIFACT_DOMAIN=gamma-aodn-org-au
CODEARTIFACT_REPO=maven-aodn-store
ECR_REGISTRY=450356697252.dkr.ecr.ap-southeast-2.amazonaws.com
ECR_REPOSITORY=geonetwork4
5 changes: 5 additions & 0 deletions .github/environment/staging.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AWS_REGION=ap-southeast-2
CODEARTIFACT_DOMAIN=gamma-aodn-org-au
CODEARTIFACT_REPO=maven-aodn-store
ECR_REGISTRY=450356697252.dkr.ecr.ap-southeast-2.amazonaws.com
ECR_REPOSITORY=geonetwork4
130 changes: 130 additions & 0 deletions .github/workflows/build-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Build Production

on:
push:
tags:
- v*.*.*

permissions:
id-token: write
contents: read

env:
environment_name: production

jobs:
build_push:
runs-on: ubuntu-latest
environment: production
outputs:
image_digest: ${{ steps.build_and_push.outputs.digest }}
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: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: 'codeartifact'
server-password: 'CODEARTIFACT_AUTH_TOKEN'

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
audience: sts.amazonaws.com
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}

- name: Get CodeArtifact Repository Authentication Token
run: |
TOKEN=$(aws codeartifact get-authorization-token \
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
--domain-owner ${{ steps.aws_auth.outputs.aws-account-id }} \
--region ${{ vars.AWS_REGION }} \
--query authorizationToken \
--output text)
echo "CODEARTIFACT_AUTH_TOKEN=$TOKEN" >> "$GITHUB_ENV"

- name: Get CodeArtifact Repository URL
run: |
REPO_URL=$(aws codeartifact get-repository-endpoint \
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
--repository ${{ vars.CODEARTIFACT_REPO }} \
--format maven \
--region ${{ vars.AWS_REGION }} \
--output text)
echo "CODEARTIFACT_REPO_URL=$REPO_URL" >> "$GITHUB_ENV"

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Publish Artifacts to CodeArtifact Repository
run: mvn -B deploy
env:
CODEARTIFACT_AUTH_TOKEN: ${{ env.CODEARTIFACT_AUTH_TOKEN }}
CODEARTIFACT_REPO_URL: ${{ env.CODEARTIFACT_REPO_URL }}

- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ vars.ECR_REGISTRY }}

- name: Build and Push Docker Image
id: build_and_push
uses: docker/build-push-action@v5
with:
context: .
# Only building for AMD64 for now
# platforms: linux/amd64,linux/arm64
push: true
tags: ${{ vars.ECR_REGISTRY }}/${{ vars.ECR_REPOSITORY }}:${{ github.ref_name }}

- name: Push Image Digest to SSM
run: |
aws ssm put-parameter \
--name "/apps/sample-django-app/${{ env.environment_name }}/image_digest" \
--type "String" \
--value "$digest" \
--overwrite
env:
digest: ${{ steps.build_and_push.outputs.digest }}

trigger_deploy:
runs-on: ubuntu-latest
needs: [build_push]
steps:
- name: Generate App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DEPLOY_APP_ID }}
private-key: ${{ secrets.DEPLOY_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: "appdeploy"

- name: Trigger Deploy Workflow
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
retries: 3
retry-exempt-status-codes: 204
script: |
github.rest.actions.createWorkflowDispatch({
owner: 'aodn',
repo: 'appdeploy',
workflow_id: 'deploy.yml',
ref: 'main',
inputs: {
app_name: 'geonetwork4',
environment: '${{ env.environment_name }}'
}
})
128 changes: 128 additions & 0 deletions .github/workflows/build-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Build Staging

on:
push:
branches:
- main
paths-ignore:
- '**/*.md'
- '.github/environment/**'

permissions:
id-token: write
contents: read

env:
environment_name: staging

jobs:
build_push:
runs-on: ubuntu-latest
environment: staging
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: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: 'codeartifact'
server-password: 'CODEARTIFACT_AUTH_TOKEN'

- name: Configure AWS Credentials
id: aws_auth
uses: aws-actions/configure-aws-credentials@v4
with:
audience: sts.amazonaws.com
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}

- name: Get CodeArtifact Repository Authentication Token
run: |
TOKEN=$(aws codeartifact get-authorization-token \
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
--domain-owner ${{ steps.aws_auth.outputs.aws-account-id }} \
--region ${{ vars.AWS_REGION }} \
--query authorizationToken \
--output text)
echo "CODEARTIFACT_AUTH_TOKEN=$TOKEN" >> "$GITHUB_ENV"

- name: Get CodeArtifact Repository URL
run: |
REPO_URL=$(aws codeartifact get-repository-endpoint \
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
--repository ${{ vars.CODEARTIFACT_REPO }} \
--format maven \
--region ${{ vars.AWS_REGION }} \
--output text)
echo "CODEARTIFACT_REPO_URL=$REPO_URL" >> "$GITHUB_ENV"

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ vars.ECR_REGISTRY }}

- name: Build and Push Docker Image
id: build_and_push
uses: docker/build-push-action@v5
with:
context: .
# Only building for AMD64 for now
# platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ vars.ECR_REGISTRY }}/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}
${{ vars.ECR_REGISTRY }}/${{ vars.ECR_REPOSITORY }}:latest

- name: Push Image Digest to SSM
run: |
aws ssm put-parameter \
--name "/apps/geonetwork4/${{ env.environment_name }}/image_digest" \
--type "String" \
--value "$digest" \
--overwrite
env:
digest: ${{ steps.build_and_push.outputs.digest }}

trigger_deploy:
runs-on: ubuntu-latest
needs: [build_push]
steps:
- name: Generate App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DEPLOY_APP_ID }}
private-key: ${{ secrets.DEPLOY_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: "appdeploy"

- name: Trigger Deploy Workflow
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
retries: 3
retry-exempt-status-codes: 204
script: |
github.rest.actions.createWorkflowDispatch({
owner: 'aodn',
repo: 'appdeploy',
workflow_id: 'deploy.yml',
ref: 'main',
inputs: {
app_name: 'geonetwork4',
environment: '${{ env.environment_name }}'
}
})
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run Pre-commit Checks

on:
pull_request:
branches:
- master

permissions:
id-token: write
contents: read

jobs:
pre_commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: pre-commit/[email protected]
69 changes: 69 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test

on:
pull_request:
branches:
- master
- main
paths-ignore:
- '**/*.md'
- '.github/environment/**'

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

permissions:
id-token: write
contents: read

jobs:
build_test:
runs-on: ubuntu-latest
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: Setup Docker Structure Test
run: >
curl -LO
https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64
&& chmod +x container-structure-test-linux-amd64 && sudo mv container-structure-test-linux-amd64
/usr/local/bin/container-structure-test

- name: Set Image Tag
id: set_image_tag
run: |
branch_name=${{ github.head_ref || github.ref_name }}
tag=${{ env.TAG_PREFIX}}-${branch_name//\//-}
echo "$tag"
echo "image_tag=$tag" >> $GITHUB_OUTPUT
env:
TAG_PREFIX: test

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Build Docker Image
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: image:${{ github.sha }}

- name: Test Docker Image
run: |
container-structure-test test --image image:${{ github.sha }} --config tests/config.yaml
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ replay_pid*
# Ingore local generated folders
elasticdata/
gn4_data/
src/main/generated/
.env

.idea/

**/target/
**/target/

**/.git-versioned-pom.xml
Loading
Loading