-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (165 loc) · 6.26 KB
/
dev-env-deploy.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: "Development Environment: Deploy"
on:
workflow_dispatch:
inputs:
machine:
description: 'Which machine to use'
required: true
default: 'local'
type: choice
options:
- m6a.xlarge
- m6a.2xlarge
- g4dn.2xlarge
- g4dn.xlarge
- local
image:
description: 'Production Environment'
required: true
default: 'ghcr.io/digital-defiance/sentiment-analysis-pipeline:main'
type: choice
options:
- ghcr.io/digital-defiance/sentiment-analysis-pipeline:main
- pytorch/pytorch:2.2.0-cuda11.8-cudnn8-devel # Not a production image
ami:
description: 'AMI'
required: true
default: 'ami-0450c19b7a7f6250d'
type: choice
options:
- ami-0450c19b7a7f6250d # pre-pulled container
# - ami-024f19cd618c1acb2 # base gpu ubuntu
docker_options:
required: true
description: 'Extra docker options'
default: '--user root'
type: choice
options:
- '--user root'
- '--user root --gpus all'
root_volume_size:
required: true
description: 'Size of root volume (Gb)'
default: "50"
env:
AWS_REGION: eu-south-1
jobs:
start-runner:
runs-on: ubuntu-latest
name: "Provision infrastructure"
outputs:
label: ${{ steps.set-output.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: Configure AWS credentials
if: ${{ inputs.machine != 'local' }}
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: ${{ env.AWS_REGION }}
- name: Start EC2 runner
id: start-ec2-runner
if: ${{ inputs.machine != 'local' }}
uses: digital-defiance/ec2-github-runner@feature/add-storage-option
with:
mode: start
root-volume-size: ${{ inputs.root_volume_size }}
iam-role-name: ec2-logs
pre-runner-script: | # sudo yum update -y && sudo yum install docker git libicu -y
sudo systemctl enable docker
sudo systemctl start docker
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
market-type: spot
ec2-image-id: ${{ inputs.ami }} # ami-0450c19b7a7f6250d # ami-0d1e2ba0458f0cd7a
ec2-instance-type: ${{ inputs.machine }}
subnet-id: subnet-0fc7dea0969cca860
security-group-id: sg-0c4cc0c0be64f1b08
- shell: bash
name: "Get runner tag"
id: set-output
run: |
if [[ ${{ inputs.machine }} == "local" ]]; then
echo "label=local" >> $GITHUB_OUTPUT
else
echo "label=${{ steps.start-ec2-runner.outputs.label }}" >> $GITHUB_OUTPUT
fi
deploy-vscode:
name: Deploy development environment
timeout-minutes: 1500
needs:
- start-runner
runs-on: ${{ needs.start-runner.outputs.label }}
container:
image: ${{ inputs.image }}
options: ${{ inputs.docker_options }}
env:
RUST_BACKTRACE: "full"
LIBTORCH_USE_PYTORCH: "1"
# Flag for my code
LLMVC_ENVIRONMENT: "development"
# These are consumed by MLFLow and other processes int he application
MLFLOW_TRACKING_URI: ${{ secrets.MLFLOW_TRACKING_URL }}
MLFLOW_TRACKING_USERNAME: ${{ secrets.MLFLOW_USERNAME }}
MLFLOW_TRACKING_PASSWORD: ${{ secrets.MLFLOW_PASSWORD }}
# https://github.com/PrefectHQ/prefect/issues/8047
TZ: "UTC"
# enables debug information generation to improve backtraces for build dependencies
CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG: true
steps:
- run: apt-get update
- run: apt-get install -y git
- uses: actions/checkout@v4
- name: "Configure git repository for development"
run: |
# git config --global user.email "mail@ruicampos.org"
# git config --global user.name "Rui Campos"
git config --global --add safe.directory /__w/nlp-metaformer/nlp-metaformer
git config pull.rebase false
# stuff to be moved to the production image
- run: pip install psycopg2-binary # required for mlflow to talk to postgres
- run: pip install mlflow
- run: pip install prefect-shell
# development dependencies and configuration
- run: apt update
- run: apt install libssh-dev -y
- run: apt install pkg-config -y
- run: apt install curl -y
- run: apt-get install procps -y
- uses: dtolnay/rust-toolchain@stable
- name: Find and set torch lib path
run: |
SITE_PACKAGES=$(python -c "import site; print(site.getsitepackages()[0])")
TORCH_LIB_PATH="${SITE_PACKAGES}/torch/lib"
echo "LD_LIBRARY_PATH=$TORCH_LIB_PATH" >> $GITHUB_ENV
- run: pip install pytest
- name: Login to prefect
run: yes | prefect cloud login --key ${{ secrets.PREFECT_API_KEY }} --workspace 'digital-defiance/default'
- name: Setup code CLI
run: |
curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz
tar -xf vscode_cli.tar.gz
- name: Serve VSCode
continue-on-error: true
run: ./code tunnel
stop-runner:
runs-on: ubuntu-latest
name: "Deprovision infrastructure"
needs:
- start-runner
- deploy-vscode
if: ${{ always() && inputs.machine != 'local' }}
steps:
- 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: ${{ env.AWS_REGION }}
- name: Stop EC2 runner
uses: digital-defiance/ec2-github-runner@v2
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}