This repository has been archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
56 lines (50 loc) · 2.43 KB
/
docker-image.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
name: Docker Image CI
on:
push:
branches: [ feature/enhancements ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker login Docker Build Docker Push
id: create-docker-image
env:
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
DOCKER_REGISTRY: ${{secrets.DOCKER_REGISTRY}}
DOCKER_REPOSITORY: ${{secrets.DOCKER_REPOSITORY}}
ECS_TASK_DEFINITION: ${{secrets.ECS_TASK_DEFINITION}}
GIT_HASH: ${{ github.sha }}
run: |
# Build a docker container and
# push it to Docker Hub so that it can
# be deployed to ECS.
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
docker pull $DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/} || echo 'Cache not available'
docker build --cache-from $DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/} -t $DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/}.$GIT_HASH .
docker tag $DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/}.$GIT_HASH $DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/}
docker push $DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/}
docker push $DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/}.$GIT_HASH
echo "::set-output name=image::$DOCKER_REGISTRY/$DOCKER_REPOSITORY:${GITHUB_REF##*/}.$GIT_HASH"
echo $ECS_TASK_DEFINITION > task-definition.json
- 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: ${{ secrets.AWS_REGION }}
- name: Fill in the nginx image ID in the Amazon ECS task definition
id: fill-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ secrets.CONTAINER_NAME }}
image: ${{ steps.create-docker-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.fill-task-def.outputs.task-definition }}
service: ${{ secrets.ECS_SERVICE }}
cluster: ${{ secrets.ECS_CLUSTER }}
wait-for-service-stability: true