forked from dockersamples/example-voting-app
121 lines (102 loc) · 3.49 KB
/
vote-main.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
name: Deploy vote to ECS
on:
# push:
# branches: [ master ]
# tags:
# - .*
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
AWS_REGION: eu-central-1
ECS_SERVICE: demo-ci-service
ECS_CLUSTER: test-aws-fargate
ECS_TASK_DEFINITION: .aws/demo-ci.json
CONTAINER_NAME: demo-ci-container
ECR_REPOSITORY: victor-test
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
jobs:
test:
runs-on: ubuntu-latest
name: Test
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Test job
run: |
echo "This is the test job"
build:
needs: test
name: Build image and push to ECR
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag-number.outputs.tag }}
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set Tag Number
id: tag-number
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Check Tag Release
env:
RELEASE_VERSION: ${{ steps.tag-number.outputs.tag }}
run: |
echo $RELEASE_VERSION
echo ${{ steps.vars.outputs.tag }}
- 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: Login to Amazon ECR
id: login-ecr-build
uses: aws-actions/amazon-ecr-login@v1
- name: Build, and tag image
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr-build.outputs.registry }}
IMAGE_TAG: ${{ steps.tag-number.outputs.tag }}
run: |
cd vote
docker buildx build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . --platform linux/amd64
- name: Push image to Amazon ECR
id: push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr-build.outputs.registry }}
IMAGE_TAG: ${{ steps.tag-number.outputs.tag }}
run: |
echo $IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
deploy:
needs: build
name: Deploy to Dev environment
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- 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: Login to Amazon ECR
id: login-ecr-deploy
uses: aws-actions/amazon-ecr-login@v1
- 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
env:
ECR_REGISTRY: ${{ steps.login-ecr-deploy.outputs.registry }}
IMAGE_TAG: ${{ needs.build.outputs.tag }}
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true