Skip to content

Commit

Permalink
Add GitHub actions for CDK (#6)
Browse files Browse the repository at this point in the history
Add PR triggered CDK test actions and PUSH triggered CDK deployment actions

Signed-off-by: Junqiu Lei <[email protected]>
  • Loading branch information
junqiu-lei authored Mar 30, 2022
1 parent cf5af6a commit e593117
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
43 changes: 43 additions & 0 deletions .github/workflows/planet-cdk-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Planet Tiles Generation CDK CD

on:
push:
branches:
- main
paths:
- 'tiles-generation/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/[email protected]
with:
node-version: '16.x'

- name: Install cdk-cli & cdk-lib
run: |
npm install -g aws-cdk
cd tiles-generation/cdk
npm install aws-cdk-lib
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Synth CDK
run: |
cd tiles-generation/cdk
cdk synth PlanetTileGenerationStack --context TILE_S3_BUCKET=${{secrets.TILE_S3_BUCKET}}
- name: Deploy CDK
run: |
cd tiles-generation/cdk
cdk deploy PlanetTileGenerationStack --context TILE_S3_BUCKET=${{secrets.TILE_S3_BUCKET}} --require-approval never
64 changes: 64 additions & 0 deletions .github/workflows/test-cdk-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Test tiles generation CDK CD and ECS task run

on:
pull_request_target:
branches:
- main
paths:
- 'tiles-generation/**'

jobs:
approve:
runs-on: ubuntu-latest

steps:
- name: Approve
run: echo With security reasons, pull request need to be approved before running actions.

build:
runs-on: ubuntu-latest

needs: [approve]
environment:
name: Pull Request
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2

- name: Use Node.js
uses: actions/[email protected]
with:
node-version: '16.x'

- name: Install cdk-cli & cdk-lib
run: |
npm install -g aws-cdk
cd tiles-generation/cdk
npm install aws-cdk-lib
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Synth CDK
run: |
cd tiles-generation/cdk
cdk synth TestTileGenerationStack --context TILE_S3_BUCKET=${{secrets.TILE_S3_BUCKET}}
- name: Deploy CDK
run: |
cd tiles-generation/cdk
cdk deploy TestTileGenerationStack --context TILE_S3_BUCKET=${{secrets.TILE_S3_BUCKET}} --outputs-file ./cdk-outputs.json --require-approval never
- name: Run ECS task
run: |
ClusterName=`jq -r '.TestTileGenerationStack .ClusterName' tiles-generation/cdk/cdk-outputs.json`
CapacityProviderName=`jq -r '.TestTileGenerationStack .CapacityProviderName' tiles-generation/cdk/cdk-outputs.json`
TaskDefinitionArn=`jq -r '.TestTileGenerationStack .TaskDefinitionArn' tiles-generation/cdk/cdk-outputs.json`
aws ecs run-task --cluster $ClusterName --task-definition $TaskDefinitionArn --capacity-provider-strategy capacityProvider=$CapacityProviderName
1 change: 1 addition & 0 deletions tiles-generation/cdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules
cdk.context.json
.cdk.staging
cdk.out
cdk-outputs.json
2 changes: 1 addition & 1 deletion tiles-generation/cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The tiles generation stack builds a raster map tiles generation pipeline on [Amazon ECS](https://aws.amazon.com/ecs/) using [AWS CDK](https://aws.amazon.com/cdk/). The docker base image used in ECS comes from the [openstreetmap-tile-server](https://github.com/Overv/openstreetmap-tile-server) project.

## Diagram
![alt text](./tiles-generation-diagram.png).
![alt text](./tiles-generation-diagram.png)

Step1: Deploy CDK stack, prepare AWS resources, it will:
* Build and upload docker image to ECR
Expand Down

0 comments on commit e593117

Please sign in to comment.