-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (75 loc) · 2.44 KB
/
develop-publish.yaml
File metadata and controls
88 lines (75 loc) · 2.44 KB
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
name: Continuous Deployment
on:
push:
branches: ["dev"]
workflow_dispatch:
inputs:
logLevel:
description: "Log level"
required: true
default: "warning"
type: choice
options:
- info
- warning
- error
environment:
description: "Environment"
required: false
type: environment
permissions:
contents: read
jobs:
docker:
name: Deploy Docker Image
runs-on: ubuntu-latest
env:
REPO: ${{ secrets.DOCKER_REPO }}
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: set version from on push tags
run: |
TAG=${{ github.event.ref }}
VERSION=${TAG#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: build docker
run: ./gradlew bootBuildImage --imageName=$REPO
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Publish Docker Image
run: |
docker push $REPO:latest
- name: Get Github Actions IP
id: ip
uses: haythem/public-ip@v1.2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_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 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: SSH Commands
uses: appleboy/ssh-action@v0.1.6
with:
host: ${{ secrets.AWS_SSH_HOST }}
username: ${{ secrets.AWS_SSH_USERNAME }}
password: ${{ secrets.AWS_SSH_PASSWORD }}
port: ${{ secrets.AWS_SSH_PORT }}
script: |
./run_80000coding_backend.sh
- name: Remove Github Actions IP From Security Group
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32