Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/CD Pipeline Construction #5

Merged
merged 4 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/backend-pr-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI for Pull Request Test

on:
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
CI:
runs-on: ubuntu-latest
env:
CI: true
steps:

- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# Gradle caching
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Create application-prod.yml file
run: |
mkdir -p ./src/main/resources
touch ./src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application-prod.yml
cat ./src/main/resources/application-prod.yml

# Gradle build
- name: Build with Gradle
run: ./gradlew build -x test
49 changes: 49 additions & 0 deletions .github/workflows/backend-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI/CD using GitHub Actions & Docker

on:
push:
branches: [ "main" ]

jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'

- name: Create directory and file if not exist
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application-prod.yml

- name: Set executable permission
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew bootJar

- name: Docker build & push to prod
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์„ ํƒ ๐Ÿ”Ž

๊นŒ๋จน์„๊นŒ๋ด ์„ ํƒ์œผ๋กœ ๋‚จ๊ฒผ๊ณ  ์ ์šฉํ•˜์ง€ ์•Š์•„๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค

๋„์ปค ์ด๋ฏธ์ง€ ํƒœ๊ทธ ๊ฐ™์€ ๋ถ€๋ถ„์€ ๋‚˜์ค‘์— ๋ฆด๋ฆฌ์ฆˆ ๊ด€๋ฆฌ๋ฅผ ํ•œ๋‹ค๊ณ  ํ•˜๋ฉด ๋ณ€๊ฒฝํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๊ธฐ๋Š” ํ•ฉ๋‹ˆ๋‹ค
๋‹ค๋งŒ ๋ฆด๋ฆฌ์ฆˆ ๊ด€๋ฆฌ ์ž์ฒด์— ๋Œ€ํ•œ ์ปจ๋ฒค์…˜์„ ์•ˆ ์ •ํ–ˆ์œผ๋‹ˆ ๊ทธ๋Œ€๋กœ ์ง„ํ–‰ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ค, ํ˜„์žฌ๋Š” ๊ฐ„๋‹จํžˆ ๋ฐฐํฌ๋ฅผ ์ž๋™ํ™”ํ•˜๋Š” ๋ฐ ์ดˆ์ ์„ ๋งž์ถ”์—ˆ์Šต๋‹ˆ๋‹ค. ์ถ”ํ›„ ๋ฆด๋ฆฌ์ฆˆ ๊ด€๋ฆฌ ์ปจ๋ฒค์…˜์„ ๋„์ž…ํ•  ๋•Œ ์ด๋ฏธ์ง€ ํƒœ๊ทธ ๊ด€๋ฆฌ๋ฅผ ํ•จ๊ป˜ ๊ฐœ์„ ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

docker push ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT

- name: Deploy to prod
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
Comment on lines +38 to +42
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์งˆ๋ฌธ ๐Ÿ’ฌ

Self Hosted Runner ๊ฐ™์€๊ฑธ ์‚ฌ์šฉํ• ์ˆ˜๋„ ์žˆ์œผ์…จ์„ํ…๋ฐ , ssh-action์„ ์‚ฌ์šฉํ•ด AWS ํ‚ค๋กœ ์™ธ๋ถ€์—์„œ ์ ‘์†ํ•ด CD ๊ณผ์ •์„ ์ง„ํ–‰ํ•˜๋Š” ๋ฐฉ์‹์„ ์„ ํƒํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํฐ ์ด์œ ๋Š” ์—†๊ณ  AWS ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ์„œ๋ฒ„์—๋งŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

envs: GITHUB_SHA
script: |
sudo docker stop spaced
sudo docker rm spaced
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์งˆ๋ฌธ ๐Ÿ’ฌ

pull ์ „์— ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•˜๋‹ˆ๊นŒ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๊ธฐ๋Š” ํ•œ๋ฐ...ํ˜น์‹œ ๋ชฐ๋ผ์„œ ๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๋ฅผ ์‹ ๊ฒฝ ์“ฐ์ง€ ์•Š์•„๋„ ๊ดœ์ฐฎ์„์ง€ ์งˆ๋ฌธ ๋“œ๋ฆฝ๋‹ˆ๋‹ค

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜„์žฌ ์„ค์ •์—์„œ๋Š” ์ด๋ฏธ์ง€๋ฅผ pullํ•˜๊ธฐ ์ „์— ๊ธฐ์กด ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•˜๊ณ  ์žˆ์–ด ๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๊ฐ€ ๋‚จ์ง€ ์•Š๋„๋ก ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋‚˜ ์กฐ๊ธˆ ๋” ์•ˆ์ „ํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ์ •๋ฆฌํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ์— ์ถ”๊ฐ€ํ•ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”, ์ฐธ๊ณ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค~

sudo docker pull ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT
sudo docker run -d -p 8080:8080 --name spaced ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT
Loading