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

Devops cicd #4

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
073fe6a
update .gitignore with tf/tg rules
digorgonzola Dec 19, 2023
e1b0282
add .pre-commit-config.yaml
digorgonzola Dec 19, 2023
d1ed20d
formatting fixes for existing code
digorgonzola Dec 19, 2023
162806a
initial commit for deployment code
digorgonzola Dec 19, 2023
2a6ec1b
init commit for github workflows
digorgonzola Dec 19, 2023
254fb49
github env vars for dev: update env name to tf_development (temporarily)
digorgonzola Dec 19, 2023
c5e7c66
deploy-development.yml: allow workflow dispatch
digorgonzola Dec 19, 2023
f985f43
deploy-development.yml: temporary push event response
digorgonzola Dec 19, 2023
76d91e7
github vars: update app_port to 8000
digorgonzola Dec 19, 2023
09046de
deploy-development.yml: update environment
digorgonzola Dec 19, 2023
dfad7a7
add sample docker structure tests
digorgonzola Dec 19, 2023
42b2d08
deploy/tf: fix container health check
digorgonzola Dec 19, 2023
b03d467
deploy-development.yml: export TF_VAR variables with correct case
digorgonzola Dec 19, 2023
1c4d490
tf: update health-check
digorgonzola Dec 19, 2023
2020fff
deploy/github: update app port to 8080
digorgonzola Dec 19, 2023
2a443ee
tg: prefer use of tfvars.json for variable overrides
digorgonzola Dec 19, 2023
083efb7
tf/service: add health_check_path variable
digorgonzola Dec 19, 2023
38de6e8
github: remove TF_VAR from env file
digorgonzola Dec 19, 2023
dae6955
tf: support advanced health check parameters
digorgonzola Dec 19, 2023
dd88292
default.auto.tfvars.json: add further default vars
digorgonzola Dec 19, 2023
eefa545
github: update development.env values
digorgonzola Dec 19, 2023
e5dc0a4
default.env: include additional variables
digorgonzola Dec 19, 2023
fa66b11
default.auto.tfvars.json: increase mem to 3GB
digorgonzola Dec 19, 2023
7676676
update container vars
digorgonzola Dec 19, 2023
442c93c
tf: support passing secrets to container definition
digorgonzola Dec 20, 2023
5c3d377
tg: remove default.auto.tfvars.json
digorgonzola Dec 20, 2023
cb19b0f
tg: gather override vars + secrets from environment
digorgonzola Dec 20, 2023
506d7ef
deploy: add in environment tf vars + secrets
digorgonzola Dec 20, 2023
b9a3501
deploy: add symlink to development (temporary workaround)
digorgonzola Dec 20, 2023
069e76d
tf_vars: merge secrets in variables.yaml
digorgonzola Dec 20, 2023
2f3e648
tf: update var name to container_secrets
digorgonzola Dec 20, 2023
d017daa
tg: remove secrets (merged into vars)
digorgonzola Dec 20, 2023
82712af
major refactor to avoid the github variables mess
digorgonzola Dec 20, 2023
9d97a94
assign correct permissions to task_exec role for pulling s3 env files
digorgonzola Dec 20, 2023
6d6598b
update development.env variables
digorgonzola Dec 20, 2023
90bad3a
github workflows: add step to sync .env files to s3
digorgonzola Dec 20, 2023
4139231
remove deployment from app repo
digorgonzola Dec 29, 2023
c3e19e8
Merge pull request #6 from aodn/devops_cicd_no_deploy
digorgonzola Dec 29, 2023
3847a9f
.pre-commit-config.yaml: remove terraform checks
digorgonzola Jan 1, 2024
ad498f3
update github workflows
digorgonzola Jan 1, 2024
0648459
update pre-commit.yml: remove terragrunt/terraform
digorgonzola Jan 24, 2024
f38aeb5
github: add separate test workflow
digorgonzola Jan 24, 2024
b7dd4d0
github: refactor build jobs
digorgonzola Jan 24, 2024
6390796
github builds: remove unncessary extra build
digorgonzola Jan 24, 2024
8051b6d
github: add .env files for environment variables
digorgonzola Jan 24, 2024
843f454
add README.md for github variable .env files
digorgonzola Jan 24, 2024
9b36555
test.yml: make docker build steps more generic
digorgonzola Jan 24, 2024
27d8c80
test.yml: rename job to "build_test"
digorgonzola Jan 24, 2024
a48ee1b
github: ignore changes to .md files
digorgonzola Jan 24, 2024
c27e7b5
github: further paths to ignore
digorgonzola Jan 24, 2024
74b0110
github: update workflows with deploy trigger
digorgonzola Feb 7, 2024
c88c1a6
Revert "update .gitignore with tf/tg rules"
digorgonzola Feb 7, 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

```
3 changes: 3 additions & 0 deletions .github/environment/production.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AWS_REGION=ap-southeast-2
ECR_REGISTRY=450356697252.dkr.ecr.ap-southeast-2.amazonaws.com
ECR_REPOSITORY=geonetwork4
3 changes: 3 additions & 0 deletions .github/environment/staging.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AWS_REGION=ap-southeast-2
ECR_REGISTRY=450356697252.dkr.ecr.ap-southeast-2.amazonaws.com
ECR_REPOSITORY=geonetwork4
102 changes: 102 additions & 0 deletions .github/workflows/build-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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'

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

- 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: 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 }}'
}
})
113 changes: 113 additions & 0 deletions .github/workflows/build-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Build Staging

on:
push:
branches:
- master
- main
paths-ignore:
- '**/*.md'
- '.github/environment/**'
# This is only here for testing purposes while in a PR
#TODO remove before merge to main
pull_request:
branches:
- master
- 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'

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

- 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: 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 }}

- 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
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
# Security
- id: detect-private-key
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.0
hooks:
- id: gitleaks
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repo is used to customize a GeoNetwork4 to be used by AODN. The key customi
build a jar file with the code we want to add and insert it use COPY function to copy it to the lib
folder during the Dockerfile build.

The jar file contains a hack where we name a @Configuration class with the same package as
The jar file contains a hack where we name a @Configuration class with the same package as
geonetwork4 base package (org.fao.geonet), so that the initial component-scan will pick up this
class. From there we add additional component-scan to our custom classes. This avoided the need
to alter the xml like what we did before plus we are using a Docker base image of GeoNetwork4.
Expand All @@ -29,6 +29,6 @@ Once you have the json, you can generate code like the one here in Java to acces

## Use of S3

You can see a config file related to S3, however we do not use it because after experiment it, it
You can see a config file related to S3, however we do not use it because after experiment it, it
didn't support well as the GN4 will issue warning on file not found with relative folder name. The
code is just keep as a record.
code is just keep as a record.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ aodn.geonetwork4.esIndexer.protocol=http
aodn.geonetwork4.esIndexer.host=${INDEXER_HOST:localhost}
aodn.geonetwork4.esIndexer.port=${INDEXER_PORT:80}
aodn.geonetwork4.esIndexer.apikey=${INDEXER_APIKEY}
aodn.geonetwork4.esIndexer.urlIndex=${aodn.geonetwork4.esIndexer.protocol}://${aodn.geonetwork4.esIndexer.host}:${aodn.geonetwork4.esIndexer.port}/api/v1/indexer/index/{uuid}
aodn.geonetwork4.esIndexer.urlIndex=${aodn.geonetwork4.esIndexer.protocol}://${aodn.geonetwork4.esIndexer.host}:${aodn.geonetwork4.esIndexer.port}/api/v1/indexer/index/{uuid}
2 changes: 1 addition & 1 deletion src/main/resources/schema/gn4-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -22473,4 +22473,4 @@
}
}
}
}
}
1 change: 0 additions & 1 deletion startEsLocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ fi
# If you run in EC2, you need to change the docker-es-compose.yml localhost in cert to the hostname of EC2 and install docker
# docker-compose and sudo chmod 666 /run/docker.sock
docker-compose -f docker-es-compose.yml up --detach

Loading