-
Notifications
You must be signed in to change notification settings - Fork 5
71 lines (58 loc) · 2.25 KB
/
up.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
on:
pull_request:
branches: [main]
types: [opened, reopened, synchronize, edited]
jobs:
up:
name: Deploy PR to ephemeral environment
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Source Configuration
working-directory: ./.github/workflows
run: |
# make input envvars available to all steps
source config.env
echo "AWS_REGION=${AWS_REGION}" >> $GITHUB_ENV
echo "AWS_ROLE=${AWS_ROLE}" >> $GITHUB_ENV
echo "TF_BACKEND_S3_BUCKET=${TF_BACKEND_S3_BUCKET}" >> $GITHUB_ENV
environment=${GITHUB_HEAD_REF##*/}
echo "ENVIRONMENT=${environment}" >> $GITHUB_ENV
- name: Assume AWS IAM Role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE }}
- name: Install Terraform CLI
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.2.9
terraform_wrapper: false
- name: Lambda-ify
run: echo "COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.7.1 /lambda-adapter /opt/extensions/lambda-adapter" >> Dockerfile
- name: Deploy to ephemeral environment
id: furl
working-directory: ./.github/workflows
run: |
terraform init \
-backend-config="bucket=${TF_BACKEND_S3_BUCKET}" \
-backend-config="key=${ENVIRONMENT}.tfstate"
terraform apply -auto-approve \
-var="name=${{ github.event.repository.name }}" \
-var="environment=${ENVIRONMENT}" \
-var="image_tag=${GITHUB_SHA}"
echo "Url=$(terraform output -json | jq '.endpoint_url.value' -r)" >> $GITHUB_OUTPUT
- name: Add HTTPS endpoint to PR comment
uses: mshick/add-pr-comment@v1
with:
message: |
:rocket: Code successfully deployed to a new ephemeral containerized PR environment!
${{ steps.furl.outputs.Url }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: "github-actions[bot]"
allow-repeats: true