Skip to content

Commit

Permalink
Merge pull request #16 from Gamegoo-repo/cd/10
Browse files Browse the repository at this point in the history
[Cd/10] Docker, Elastic Beanstalk 활용한 무중단 CICD 구축
  • Loading branch information
rimi3226 authored May 10, 2024
2 parents 1812eb6 + c8dc361 commit 64fbbcb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
53 changes: 19 additions & 34 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
name: Java CI with Gradle & Docker
name: Java CICD with Gradle & Docker

on:
push:
branches: [ "develop", "feat/*", "cicd/*", "fix/*", "hotfix/*", "refactor/*", "chore/*", "docs/*", "style/*", "test/*" ]
branches: [ "develop", "feat/*", "cd/*", "fix/*", "hotfix/*", "refactor/*", "chore/*", "docs/*", "style/*", "test/*" ]
pull_request:
types : [ closed ]
workflow_dispatch: # 수동 실행 가능
jobs:
build:
build-and-push-image:
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'
java-version: '17'
distribution: 'temurin'

- name: Checkout
uses: actions/checkout@v3
Expand All @@ -42,11 +39,6 @@ jobs:
- name: docker Hub push
run: docker push rimi3226/gamegoo

# GET GitHub IP (5)
- name: get GitHub IP
id: ip
uses: rimi3226/[email protected]

# Configure AWS Credentials (6) - AWS 접근 권한 취득(IAM)
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -55,26 +47,19 @@ jobs:
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
# Build 번호 부여 (7)
- name: Build Number
id: build-number
run: echo "::set-output name=BUILD_NUMBER::$(date '+%-d.%-m.%Y.%-H.%-M.%-S')"

# AWS EC2 Server Connect & Docker 명령어 실행 (8)
- name: AWS EC2 Connection
uses: appleboy/[email protected]
# Elastic Beanstalk Deploy with docker (8)
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v20
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
password: ${{ secrets.EC2_PASSWORD }}
port: ${{ secrets.EC2_SSH_PORT }}
timeout: 60s
script: |
sudo docker stop boot-prac-ci
sudo docker rm boot-prac-ci
sudo docker run -it -d -p 8080:8080 --name boot-prac-ci lucaskang134/boot-prac-ci
# 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
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: Gamegoo
environment_name: Gamegoo-env
region: ap-northeast-2
version_label: ${{ steps.build-number.outputs.BUILD_NUMBER }}
deployment_package: ./elasticbeanstalk/docker-compose.yml
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.7'
id 'com.google.cloud.tools.jib' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.4'
}

jib{
from{
image="adoptopenjdk/openjdk16:x86_64-alpine-jdk-16.0.1_9"
}
to{
image="rimi3226/gamegoo2"
tags=["latest"]
}
}

group = 'com'
version = '0.0.1-SNAPSHOT'
//sourceCompatibility = '17'
Expand Down
7 changes: 7 additions & 0 deletions elasticbeanstalk/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3.8"
services:
backend:
image: "rimi3226/gamegoo"
ports:
- "80:8080"
restart: "always"
2 changes: 1 addition & 1 deletion src/main/java/com/gamegoo/controller/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TestController {
@GetMapping("/test/hello")
@Operation(summary = "swagger 테스트용 API 입니다.", description = "simple API for swagger test!")
public String hello() {
return "Swagger Setting Success!";
return "Swagger Setting Success%%!";
}

@GetMapping("/test/error")
Expand Down

0 comments on commit 64fbbcb

Please sign in to comment.