-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (80 loc) · 3.07 KB
/
aws_lambda.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Helios Traceker AWS Lambda Deployment
run-name: ${{ github.actor }} is deploying HeliosTracker to AWS 🚀
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Set up HeliosTracker repository
uses: actions/checkout@v3
with:
path: heliostracker
- name: Set up ConEd repository
uses: actions/checkout@v3
with:
repository: varming/coned
path: coned
- name: Set up Python
uses: actions/setup-python@v3
with:
architecture: 'x64'
python-version: '3.9'
cache: pip
cache-dependency-path: |
**/requirements*.txt
- name: Setup environment
run: |
python3 -m venv env
- name: Fetch Python dependencies
run: |
source env/bin/activate
pip install -r coned/requirements.txt
pip install -r heliostracker/requirements.txt
- name: Package program
run: |
cp -r heliostracker/src/* env/.
- name: Build artifact
run: |
pushd env/lib/python3.9/site-packages
zip -r ../../../../package.zip .
popd
zip -g package.zip heliostracker/src/*
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: package.zip
deploy:
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: package.zip
- name: Configure AWS
run: |
set -eu -o pipefail
umask 177
export AWS_ROLE_ARN=arn:aws:iam::162141084993:role/GithubActions
export AWS_WEB_IDENTITY_TOKEN_FILE=$(mktemp -q awscreds.XXXXXX)
export AWS_DEFAULT_REGION=us-east-1
echo AWS_WEB_IDENTITY_TOKEN_FILE=$AWS_WEB_IDENTITY_TOKEN_FILE >> $GITHUB_ENV
echo AWS_ROLE_ARN=$AWS_ROLE_ARN >> $GITHUB_ENV
echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION >> $GITHUB_ENV
curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r '.value' > $AWS_WEB_IDENTITY_TOKEN_FILE
- name: Deploy via AWS CloudFormation
run: |
aws sts get-caller-identity
STAMP="$(date "+%Y-%m-%dT%H:%M:%S")-$(uuidgen)"
aws s3 cp package.zip "s3://heliostracker-deployments-162141084993/HeliosTracker/$STAMP/templates/package.zip"
aws s3 cp heliostracker/templates/heliostracker.yml "s3://heliostracker-deployments-162141084993/HeliosTracker/$STAMP/templates/heliostracker.yml"
aws cloudformation create-change-set --stack-name HeliosTracker --template-url "s3://heliostracker-deployments-162141084993/HeliosTracker/$STAMP/templates/heliostracker.yml" --capabilities CAPABILITY_IAM,CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND --change-set-name "HeliosTracker-$STAMP"
aws cloudformation describe-change-set --stack-name HeliosTracker --change-set-name "HeliosTracker-$STAMP"
aws cloudformation execute-change-set --stack-name HeliosTracker --change-set-name "HeliosTracker-$STAMP"