Skip to content

[feat] 태그 API 구현 (#71) #25

[feat] 태그 API 구현 (#71)

[feat] 태그 API 구현 (#71) #25

# Reference
# - (1) https://docs.docker.com/build/ci/github-actions/#examples
# - (2) https://github.com/Kernel360/E2E2-LOOK-US/blob/deploy/.github/workflows/deploy.yml
name: Tech-pick Testing Server Deploy
on:
push:
branches:
- "backend" # Backend 브랜치
jobs:
build:
runs-on: ubuntu-latest
steps:
-
# 저장소 Checkout
name: Checkout source code
uses: actions/checkout@v4
-
# Gradle 실행 권한 부여
name: Grant execute permission to gradlew
run: chmod +x ./backend/gradlew
-
# JDK 설치
name: Set up JDK corretto:17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
-
# Spring boot application 빌드
name: Build with gradle
run: |
cd ./backend
./gradlew clean build -x test
-
# Docker image 빌드
name: Build docker image
run: |
cd ./backend
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/techpick:${{ github.sha }} .
-
# Docker hub 로그인
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
# Docker hub 업로드
name: Publish to docker hub
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/techpick:${{ github.sha }}
-
# 서버 ssh 접속 후 방금 올린 이미지 pull 받고 실행
name: Deploy on Test-Server
uses: appleboy/ssh-action@master
with:
host: minlife.me # test home server
port: 4242
username: root # root user
password: ${{ secrets.SSH_TEST_SERVER_KYEU_PASSWORD }}
script: |
echo "login docker hub for private repository access ..."
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
echo "docker - pulling..."
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/techpick:${{ github.sha }}
echo "docker - changing image name and tag ..."
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/techpick:${{ github.sha }} techpick:staging
cd /home/project/techpick
echo "create .env file with github repository's ENV setting ..."
rm -rf .env
touch .env
echo "DOCKER_MYSQL_DATABASE=${{ secrets.DOCKER_MYSQL_DATABASE }}" >> .env
echo "DOCKER_MYSQL_URL=${{ secrets.DOCKER_MYSQL_URL }}" >> .env
echo "DOCKER_MYSQL_USERNAME=${{ secrets.DOCKER_MYSQL_USERNAME }}" >> .env
echo "DOCKER_MYSQL_PASSWORD=${{ secrets.DOCKER_MYSQL_PASSWORD }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" >> .env
echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> .env
echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> .env
echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" >> .env
echo "KAKAO_CLIENT_SECRET=${{ secrets.KAKAO_CLIENT_SECRET }}" >> .env
echo "NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}" >> .env
echo "NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}" >> .env
docker-compose down
docker compose up -d
echo "docker - pruning images that passed 24h ..."
docker image prune -af --filter "until=24h"
-
# 배포 Action 실행 결과 깃허브 알림
name: Discord Webhook Action
uses: sarisia/actions-status-discord@v1.14.7
if: always()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: ${{ job.status }}
title: "Deployment Action Result"
description: "테스트 API 서버 배포 action 결과"
color: 0xff91a4
url: "https://github.com/sarisia/actions-status-discord"
username: GitHub Actions