Skip to content

Commit

Permalink
Merge pull request #162 from CEOS-Developers/refact/os-migration
Browse files Browse the repository at this point in the history
[refact] os migration
  • Loading branch information
mushroom1324 authored Dec 18, 2023
2 parents e5dcc1c + 8d32cdb commit 695bb46
Showing 1 changed file with 108 additions and 62 deletions.
170 changes: 108 additions & 62 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ permissions:

jobs:
build:
runs-on: ubuntu-latest
# runs-on을 ubuntu-lastest에서 변경했음
# 참고자료 https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: linux
steps:
# 기본 체크아웃
- name: Checkout
Expand All @@ -23,43 +25,9 @@ jobs:
java-version: '17'
distribution: 'temurin'

# 그래들 캐싱
- 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: Make application-secret.yml without env
run: |
touch ./src/main/resources/application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_DEV }}" > ./src/main/resources/application-secret.yml
env:
PROPERTIES_DEV: ${{ secrets.APPLICATION_SECRET_DEV }}

- name: Make env
run: |
touch .env
echo "${{ secrets.ENV_DEV }}" > .env
env:
PROPERTIES_DEV: ${{ secrets.ENV_DEV }}

# Gradle build
## gradle build
- name: Build with Gradle
run: ./gradlew build -x test :spotlessApply

- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ceos/ceos-server-dev

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
run: ./gradlew bootJar

- name: Login to DockerHub
uses: docker/login-action@v1
Expand All @@ -76,34 +44,112 @@ jobs:
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/ceos-backend-dev

- name: create remote directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST_DEV }}
username: ubuntu
key: ${{ secrets.EC2_KEY_DEV }}
script: mkdir -p ~/srv/ubuntu/ceos_web_dev

- name: copy source via ssh key
uses: burnett01/[email protected]
with:
switches: -avzr --delete
remote_path: ~/srv/ubuntu/
remote_host: ${{ secrets.EC2_HOST_DEV }}
remote_user: ubuntu
remote_key: ${{ secrets.EC2_KEY_DEV }}

# ssh 접근 후 docker 이미지 pull 및 컨테이너 재시작
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST_DEV }}
username: ubuntu
username: ec2-user # ubuntu 에서 변경
key: ${{ secrets.EC2_KEY_DEV }}
script: |
sh ~/srv/ubuntu/config/scripts/deploy.sh
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
sudo docker rmi $(sudo docker images -q)
sudo docker-compose -f ~/srv/ubuntu/docker-compose.dev.yml pull
sudo docker-compose -f ~/srv/ubuntu/docker-compose.dev.yml up --build -d
cd /home/ec2-user/ceos
sudo touch .env
echo "${{ secrets.ENV_DEV }}" > .env
sudo curl -o docker-compose.yml https://raw.githubusercontent.com/CEOS-Developers/CEOS-BE/dev/docker-compose.dev.yml
sudo chmod 666 /var/run/docker.sock
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/ceos-backend-dev
docker-compose -f docker-compose.dev.yml --env-file ./.env up -d
docker image prune -f
# 주석 처리함 (레거시 코드)
#
# # 그래들 캐싱
# - 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: Make application-secret.yml without env
# run: |
# touch ./src/main/resources/application-secret.yml
# echo "${{ secrets.APPLICATION_SECRET_DEV }}" > ./src/main/resources/application-secret.yml
# env:
# PROPERTIES_DEV: ${{ secrets.APPLICATION_SECRET_DEV }}
#
# - name: Make env
# run: |
# touch .env
# echo "${{ secrets.ENV_DEV }}" > .env
# env:
# PROPERTIES_DEV: ${{ secrets.ENV_DEV }}
#
# # Gradle build
# - name: Build with Gradle
# run: ./gradlew build -x test :spotlessApply
#
# - name: Docker meta
# id: docker_meta
# uses: crazy-max/ghaction-docker-meta@v1
# with:
# images:
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
#
# - name: Login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
#
# - name: Docker build & push
# uses: docker/build-push-action@v2
# with:
# context: .
# file: ./Dockerfile
# platforms: linux/amd64
# push: true
# tags: ${{ secrets.DOCKER_USERNAME }}/ceos-backend-dev
#
# - name: create remote directory
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.EC2_HOST_DEV }}
# username: ubuntu
# key: ${{ secrets.EC2_KEY_DEV }}
# script: mkdir -p ~/srv/ubuntu/ceos_web_dev
#
# - name: copy source via ssh key
# uses: burnett01/[email protected]
# with:
# switches: -avzr --delete
# remote_path: ~/srv/ubuntu/
# remote_host: ${{ secrets.EC2_HOST_DEV }}
# remote_user: ubuntu
# remote_key: ${{ secrets.EC2_KEY_DEV }}
#
# - name: executing remote ssh commands using password
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.EC2_HOST_DEV }}
# username: ubuntu
# key: ${{ secrets.EC2_KEY_DEV }}
# script: |
# sh ~/srv/ubuntu/config/scripts/deploy.sh
# sudo docker stop $(sudo docker ps -a -q)
# sudo docker rm $(sudo docker ps -a -q)
# sudo docker rmi $(sudo docker images -q)
# sudo docker-compose -f ~/srv/ubuntu/docker-compose.dev.yml pull
# sudo docker-compose -f ~/srv/ubuntu/docker-compose.dev.yml up --build -d

0 comments on commit 695bb46

Please sign in to comment.