-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (79 loc) · 2.55 KB
/
build_and_deploy.yaml
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
94
95
96
97
98
99
100
name: Build infra and deploy app
on:
workflow_dispatch
env:
ARTIFACTS_PATH: artifacts
AWS_DEFAULT_REGION: eu-west-1
ECR_REPO: pandas-polars-pyspark
TF_DIR: terraform
PACKAGE_NAME: ppp
POETRY_VERSION: 1.4.2
POETRY_CACHE_DIR: $CI_PROJECT_DIR/.cache/poetry
PYTHON_VERSION: 3.10.12
permissions:
id-token: write
contents: write
jobs:
build_terraform:
name: Build terraform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ vars.AWS_WORKFLOW_ROLE }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
- name: Terraform init
run: terraform init
working-directory: ${{ env.TF_DIR }}
- name: Terraform validate
run: terraform validate
working-directory: ${{ env.TF_DIR }}
- name: Terraform plan
run: terraform plan
working-directory: ${{ env.TF_DIR }}
- name: Terraform apply
run: terraform apply -auto-approve
working-directory: ${{ env.TF_DIR }}
build_package:
name: Build package
runs-on: ubuntu-latest
needs: build_terraform
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ vars.AWS_WORKFLOW_ROLE }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Install poetry
run: |
pip install poetry==$POETRY_VERSION
poetry config cache-dir $POETRY_CACHE_DIR
poetry install --no-root
source `poetry env info --path`/bin/activate
- name: Build wheel
run: |
poetry build -f wheel
- name: Upload wheel as artifact
uses: actions/upload-artifact@master
with:
name: ${{ env.PACKAGE_NAME }}-package
path: "dist/${{ env.PACKAGE_NAME }}-*.whl"
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $REGISTRY/$ECR_REPO:$IMAGE_TAG .
docker push $REGISTRY/$ECR_REPO:$IMAGE_TAG