-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.92 KB
/
gradle.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
name: Java CI with Gradle & Docker
on:
push:
branches: [ "develop", "feat/*", "cd/*", "fix/*", "hotfix/*", "refactor/*", "chore/*", "docs/*", "style/*", "test/*" ]
pull_request:
types : [ closed ]
workflow_dispatch: # 수동 실행 가능
jobs:
build:
runs-on: ubuntu-latest
# develop 기반 브랜치가 PR이 merge 됐을 경우에만 진행
# 개발 이후에 if 문 붙이기.. if문 있으면 Status skipped 됨
# if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Checkout
uses: actions/checkout@v3
# Spring Boot 어플리케이션 Build (1)
- name: Spring Boot Build
run: ./gradlew clean build -x test --warning-mode=all --stacktrace
# Docker 이미지 Build (2)
- name: docker image build
run: docker build -t rimi3226/gamegoo .
# DockerHub Login (3)
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PW }}
# Docker Hub push (4)
- name: docker Hub push
run: docker push rimi3226/gamegoo
# GET GitHub IP (5)
- name: get GitHub IP
id: ip
uses: haythem/[email protected]
# Configure AWS Credentials (6) - AWS 접근 권한 취득(IAM)
- 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: ap-northeast-2
# Add github ip to AWS (7)
- name: Add GitHub IP to AWS
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
# AWS EC2 Server Connect & Docker 명령어 실행 (8)
- name: AWS EC2 Connection
uses: appleboy/ssh-action@master
with:
host : ec2-3-39-194-35.ap-northeast-2.compute.amazonaws.com
username : root
key : ${{ secrets.EC2_PEM_KEY }}
port : 22
# host: ${{ secrets.EC2_HOST }}
# username: ${{ secrets.EC2_USERNAME }}
# password: ${{ secrets.EC2_PASSWORD }}
# port: ${{ secrets.EC2_SSH_PORT }}
timeout: 50s
script: whoami
# sudo docker stop gamegoo
# sudo docker rm gamegoo
# sudo docker run -it -d -p 8080:8080 --name rimi3226 rimi3226/gamegoo
# REMOVE Github IP FROM security group (9)
- name: Remove 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