Skip to content

Commit

Permalink
build: 자동배포 스크립트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
yubin-im committed Jul 2, 2024
1 parent c573b69 commit f5b215e
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CD with Gradle

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

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- 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
shell: bash

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to docker repo
run: |
docker login -u ${{ secrets.DOCKER_USERNAME_YUB }} -p ${{ secrets.DOCKER_PASSWORD_YUB }}
docker build -f Dockerfile -t "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest" .
docker push "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest"
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo docker ps
sudo docker pull "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest"
sudo docker stop hanafun
sudo docker rm hanafun
sudo docker run -d -p 8080:8080 --name hanafun "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest"
sudo docker image prune -f

0 comments on commit f5b215e

Please sign in to comment.