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] Create gradle.yml #3 #5

Merged
merged 6 commits into from
Jan 14, 2024
Merged
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
82 changes: 82 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Java CI/CD with Gradle

on:
pull_request:
branches: ["develop"]
push:
branches: ["develop"]

jobs:
ci:
runs-on: ubuntu-lastest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:

java-version: '17'
distribution: 'temurin'

- name: Make application.yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
Copy link
Member

@oxdjww oxdjww Jan 14, 2024

Choose a reason for hiding this comment

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

μš” λ°©μ‹μœΌλ‘œ yml을 κ΄€λ¦¬ν•œλ‹€λ©΄, 기쑴에 μ œκ°€ 생성해 놓은
application-local.yml
application-prod.yml
은 μ‚­μ œν•˜κ³ , application.yml에 application-local.yml 을 λ³΅λΆ™ν•΄μ„œ 남겨놓아도 될 것 κ°™μ•„μš”! μˆ˜μ • λΆ€νƒλ“œλ¦½λ‹ˆλ‹€ πŸ‘


- name: Grant execute permission for gradlew and build
run: |
chmod +x ./gradlew
./gradlew clean
./gradlew build
cd:
runs-on: ubuntu-latest
needs: ci

steps:
- name: Checkout
uses: actions/checkout@v3

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

# Docker image Build (2)
- name: Docker image build
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/sponus-docker --pull --no-cache --platform linux/amd64 .

# DockerHub Login (3)
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Docker Hub push (4)
- name: Docker Hub push
run: docker push ${{ secrets.DOCKER_USERNAME }}/sponus-docker

# AWS EC2 Server Connect & Docker command execution (8)
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }} # EC2 instance public DNS
username: ec2-user
key: ${{ secrets.PRIVATE_KEY }} # pem key
script: |
sudo docker stop sponus-docker
sudo docker rm sponus-docker
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/sponus-docker
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/sponus-docker

sudo docker stop my-redis
sudo docker rm my-redis
sudo docker rmi redis

sudo docker pull redis
sudo docker network create my-network
sudo docker run --name my-redis --network my-network -d redis
sudo docker run -it -d -p 8080:8080 --name sponus-docker -e TZ=Asia/Seoul --network my-network ${{ secrets.DOCKER_USERNAME }}/sponus-docker