Skip to content

Commit 226b869

Browse files
committed
feat: extracted from hello-nrfcloud/backend
0 parents  commit 226b869

File tree

85 files changed

+18482
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+18482
-0
lines changed

.envrc.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export AWS_REGION=... # AWS region to use, e.g. eu-west-1
2+
export AWS_DEFAULT_REGION=$AWS_REGION
3+
export AWS_ACCESS_KEY_ID= ... # Your AWS Access Key ID
4+
export AWS_SECRET_ACCESS_KEY=... # Your AWS Secret Access Key
5+
6+
# Suppress warnings caused by using the latest Node.js version
7+
export JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION=1
8+
export NODE_NO_WARNINGS=1

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @coderbyheart @pudkrong

.github/workflows/cleanup.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Cleanup
2+
3+
permissions:
4+
id-token: write
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
stackName:
10+
description: "Name of the stack to clean"
11+
required: true
12+
openssl_lambda_tag:
13+
description: "OpenSSL Lambda container tag to deploy"
14+
required: true
15+
http_api_mock_stack_name:
16+
description: "Stack name of the HTTP API mock instance"
17+
required: true
18+
env:
19+
CI: 1
20+
FORCE_COLOR: 3
21+
JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION: 1
22+
STACK_NAME: ${{ github.event.inputs.stackName }}
23+
OPENSSL_LAMBDA_CONTAINER_TAG: ${{ github.event.inputs.openssl_lambda_tag }}
24+
25+
jobs:
26+
cleanup:
27+
runs-on: ubuntu-22.04
28+
29+
timeout-minutes: 30
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- uses: actions/setup-node@v4
35+
with:
36+
node-version: "20.x"
37+
cache: "npm"
38+
39+
- name: Install dependencies
40+
run: npm ci --no-audit
41+
42+
- name: Configure AWS credentials
43+
uses: aws-actions/configure-aws-credentials@v4
44+
with:
45+
# The role is set up via https://github.com/hello-nrfcloud/ci
46+
# secrets.AWS_ACCOUNT_ID_CI is an organization secret
47+
role-to-assume: |
48+
arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_CI }}:role/${{ github.repository_owner }}-ci-${{ github.event.repository.name }}
49+
# vars.AWS_REGION_CI is an organization variable
50+
aws-region: ${{ vars.AWS_REGION_CI }}
51+
52+
- name: Delete logs
53+
run: ./cli.sh logs -X
54+
55+
- name: Destroy stack
56+
run: npx cdk destroy --all -f
57+
58+
- name: Clean up SSM parameters
59+
run: |
60+
./cli.sh configure-nrfcloud-account apiEndpoint -X
61+
./cli.sh configure-nrfcloud-account apiKey -X
62+
63+
- name: Delete ECR repositories
64+
run: |
65+
aws ecr delete-repository --force --repository-name ${{ env.STACK_NAME }}-openssl-lambda
66+
67+
cleanup-http-api-mock:
68+
runs-on: ubuntu-22.04
69+
70+
timeout-minutes: 5
71+
72+
steps:
73+
- uses: actions/checkout@v4
74+
75+
- uses: actions/setup-node@v4
76+
with:
77+
node-version: "20.x"
78+
cache: "npm"
79+
80+
- name: Configure AWS credentials
81+
uses: aws-actions/configure-aws-credentials@v4
82+
with:
83+
# The role is set up via https://github.com/hello-nrfcloud/ci
84+
# secrets.AWS_ACCOUNT_ID_CI is an organization secret
85+
role-to-assume: |
86+
arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_CI }}:role/${{ github.repository_owner }}-ci-${{ github.event.repository.name }}
87+
# vars.AWS_REGION_CI is an organization variable
88+
aws-region: ${{ vars.AWS_REGION_CI }}
89+
90+
- name: Delete HTTP API mock
91+
run: |
92+
npx @bifravst/http-api-mock destroy ${{ inputs.http_api_mock_stack_name }}

.github/workflows/deploy.yaml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Deployment
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: "Version to deploy"
8+
required: true
9+
openssl_lambda_tag:
10+
description: "OpenSSL Lambda container tag to deploy"
11+
required: true
12+
13+
permissions:
14+
id-token: write
15+
packages: write
16+
17+
env:
18+
STACK_NAME: ${{ vars.STACK_NAME }}
19+
AWS_REGION: ${{ vars.AWS_REGION }}
20+
FORCE_COLOR: 3
21+
JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION: 1
22+
REGISTRY: ghcr.io
23+
24+
jobs:
25+
print-inputs:
26+
name: Print inputs
27+
runs-on: ubuntu-22.04
28+
steps:
29+
- name: Print inputs
30+
run: |
31+
echo ref=${{ github.event.inputs.ref }}
32+
echo openssl_lambda_tag=${{ github.event.inputs.openssl_lambda_tag }}
33+
34+
docker:
35+
name: Push Docker images to ECR
36+
37+
runs-on: ubuntu-22.04
38+
39+
environment: production
40+
41+
strategy:
42+
matrix:
43+
image:
44+
- openssl-lambda
45+
include:
46+
- image: openssl-lambda
47+
tag: ${{ github.event.inputs.openssl_lambda_tag }}
48+
49+
steps:
50+
- name: Log in to the repo's container registry
51+
uses: docker/login-action@5f4866a30a54f16a52d2ecb4a3898e9e424939cf
52+
with:
53+
registry: ${{ env.REGISTRY }}
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Pull Docker image from repository registry
58+
run: |
59+
docker pull ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.image }}:${{ matrix.tag }}
60+
61+
- name: Configure AWS credentials
62+
uses: aws-actions/configure-aws-credentials@v4
63+
with:
64+
role-to-assume: ${{ secrets.AWS_ROLE }}
65+
role-session-name: github-action-hello-nrfcloud-backend
66+
aws-region: ${{ vars.AWS_REGION }}
67+
68+
- name: Get credentials for ECR
69+
id: token
70+
run: |
71+
CREDS=$(aws ecr get-authorization-token | jq -r '.authorizationData[0].authorizationToken')
72+
PARTS=($(echo $CREDS | tr ':' '\n'))
73+
TOKEN=${PARTS[1]}
74+
echo "token=$TOKEN" >> $GITHUB_OUTPUT
75+
echo "::add-mask::$TOKEN"
76+
77+
- name: Get repository on ECR
78+
id: repositoryUri
79+
run: |
80+
REPO_URI=$(aws ecr describe-repositories --repository-names ${{ env.STACK_NAME }}-${{ matrix.image }} | jq -r '.repositories[0].repositoryUri')
81+
echo "repositoryUri=$REPO_URI" >> $GITHUB_OUTPUT
82+
83+
- name: Log in to the repo's container registry
84+
uses: docker/login-action@5f4866a30a54f16a52d2ecb4a3898e9e424939cf
85+
with:
86+
registry: ${{ steps.repositoryUri.outputs.repositoryUri }}
87+
username: AWS
88+
password: ${{ steps.token.outputs.token }}
89+
90+
- name: Tag Docker image for ECR
91+
run: |
92+
docker tag ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.image }}:${{ matrix.tag }} ${{ steps.repositoryUri.outputs.repositoryUri }}:${{ matrix.tag }}
93+
94+
- name: Check if Docker image exists on ECR
95+
id: check-docker-image
96+
continue-on-error: true
97+
run: |
98+
docker manifest inspect ${{ steps.repositoryUri.outputs.repositoryUri }}:${{ matrix.tag }}
99+
100+
- name: Push Docker image to ECR
101+
if: steps.check-docker-image.outcome == 'failure'
102+
run: |
103+
docker push ${{ steps.repositoryUri.outputs.repositoryUri }}:${{ matrix.tag }}
104+
105+
deploy:
106+
runs-on: ubuntu-22.04
107+
108+
environment: production
109+
110+
needs: docker
111+
112+
env:
113+
FORCE_COLOR: 3
114+
JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION: 1
115+
OPENSSL_LAMBDA_CONTAINER_TAG:
116+
${{ github.event.inputs.openssl_lambda_tag }}
117+
118+
steps:
119+
- uses: actions/checkout@v4
120+
with:
121+
ref: ${{ github.event.inputs.ref }}
122+
123+
- name: Determine released version
124+
id: version
125+
run: |
126+
git fetch --tags
127+
VERSION=`git describe --abbrev=0 --tags --always | tr -d '\n'`
128+
echo "VERSION=$VERSION" >> $GITHUB_ENV
129+
130+
- uses: actions/setup-node@v4
131+
with:
132+
node-version: "20.x"
133+
cache: "npm"
134+
135+
- name: Install dependencies
136+
run: npm ci --no-audit
137+
138+
- name: Configure AWS credentials
139+
uses: aws-actions/configure-aws-credentials@v4
140+
with:
141+
role-to-assume: ${{ secrets.AWS_ROLE }}
142+
role-session-name: github-action-hello-nrfcloud-backend
143+
aws-region: ${{ vars.AWS_REGION }}
144+
145+
- run: npx cdk diff
146+
147+
- name: Deploy solution stack
148+
run: npx cdk deploy --all --require-approval never

0 commit comments

Comments
 (0)