-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (76 loc) · 2.95 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
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
name: Docker Image CD
on:
push:
branches: [ "main" ]
permissions:
contents: read
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Github Actions IP
id: ip
run: |
echo "ipv4=`dig TXT +short o-o.myaddr.l.google.com @ns1.google.com`" >> "$GITHUB_OUTPUT"
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 17
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 5723 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: Build the server
run: |
./enable_environment.sh
- name: Remove Github Actions IP From Security Group
continue-on-error: true
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 5723 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- id: commit
uses: pr-mpt/actions-commit-hash@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_PASSWORD}}
- name: Build and push
env:
TAG: ${{ env.GITHUB_SHA }}
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{secrets.DOCKER_HUB_USERNAME}}/${{ vars.REPOSITORY_NAME }}:latest, ${{secrets.DOCKER_HUB_USERNAME}}/${{ vars.REPOSITORY_NAME }}:${{ steps.commit.outputs.short }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: AWS Secrets Manager GitHub Action
uses: aws-actions/[email protected]
with:
secret-ids: dev/esc/chat/task_definition
- name: task definition to file
run: |
echo '${{ env.DEV_ESC_CHAT_TASK_DEFINITION }}' >> task_definition.json
- name: Amazon ECS "Deploy Task Definition" Action for GitHub Actions
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: task_definition.json
service: ${{ vars.SERVICE_NAME }}
cluster: ${{ vars.CLUSTER_NAME }}
wait-for-service-stability: true
wait-for-minutes: 10