ㅋㅋ #127
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
on: | |
push: | |
branches: | |
- 'master' | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GIT_TOKEN }} | |
submodules: true | |
- name: Setup Java 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Update Git submodules | |
run: git submodule update --remote --recursive | |
# - name: Build and test with Gradle | |
# run: ./gradlew test | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_ID }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build and push Docker image | |
run: ./gradlew jib | |
- name: SSH into EC2 instance | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
script: | | |
echo ${{ secrets.DOCKER_HUB_TOKEN }} | sudo docker login -u ${{ secrets.DOCKER_HUB_ID }} --password-stdin | |
sudo docker pull ${{ secrets.IMAGE_REPO_URL }} | |
sudo docker ps -f name=ggsdh-api -q | xargs --no-run-if-empty sudo docker container stop | |
sudo docker ps -a -f name=ggsdh-api -q | xargs --no-run-if-empty sudo docker container rm | |
sudo docker run -d --log-driver=awslogs --log-opt awslogs-region=ap-northeast-2 --log-opt awslogs-group=ggsdh --name ggsdh-api -e "TZ=Asia/Seoul" -p 8080:8080 ggsdh/ggsdh-operate |