-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (68 loc) · 2.91 KB
/
deployworker.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
name: Deploy Worker to Amazon ECS/ECR
on:
workflow_dispatch:
release:
types: [published]
env:
AWS_REGION: us-west-2
ECR_WORKER_REPOSITORY: pv-validation-hub-worker
ECS_WORKER_SERVICE: worker-service
ECS_WORKER_CLUSTER: pv-validation-hub-worker-cluster-prod
WORKER_CONTAINER_NAME: pv-validation-hub-worker-task-ec2
AK: ${{ secrets.API_AK }}
SAK: ${{ secrets.API_SAK }}
DOCKER_HOST_VOLUME_DATA_DIR: ${{ vars.DOCKER_HOST_VOLUME_DATA_DIR }}
DOCKER_HOST_VOLUME_RESULTS_DIR: ${{ vars.DOCKER_HOST_VOLUME_RESULTS_DIR }}
jobs:
deploy_worker:
name: Deploy Worker
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, tag, and push image to Amazon ECR
id: build-image-worker
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.ECR_WORKER_REPOSITORY }}
IMAGE_TAG: latest
run: |
cd workers
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
--build-arg region=${{ env.AWS_REGION }} \
--build-arg ak=${{ env.AK }} \
--build-arg sak=${{ env.SAK }} \
--build-arg DOCKER_HOST_VOLUME_DATA_DIR=${{ env.DOCKER_HOST_VOLUME_DATA_DIR }} \
--build-arg DOCKER_HOST_VOLUME_RESULTS_DIR=${{ env.DOCKER_HOST_VOLUME_RESULTS_DIR }} \
-f Dockerfile.prod .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "IMAGE=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV
# needed for the task-definition.json file, update task family here
# can also use the CLI to manually generate the task, new def forces new deployment of containers
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.WORKER_CONTAINER_NAME }} --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.WORKER_CONTAINER_NAME }}
image: ${{ env.IMAGE }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_WORKER_SERVICE }}
cluster: ${{ env.ECS_WORKER_CLUSTER }}
wait-for-service-stability: true