Skip to content

fix: fixed pwd typo, add --no-deps on docker compose up #24

fix: fixed pwd typo, add --no-deps on docker compose up

fix: fixed pwd typo, add --no-deps on docker compose up #24

Workflow file for this run

# Temporary Single EC2 deployment file
name: Build test
on:
push:
branches:
github-action-test
jobs:
deploy:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: testdb
MYSQL_USER: user
MYSQL_PASSWORD: somepassword
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h localhost"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
# 1. GitHub 저장소에서 코드 가져오기
- name: Checkout Repository
uses: actions/checkout@v4
# 2. Java 및 Gradle 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
# 3. Gradle 빌드 수행
- name: Build with Gradle
run: |
chmod +x gradlew
./gradlew build
# Just for build test, not for prod!
env:
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/testdb
SPRING_DATASOURCE_USERNAME: user
SPRING_DATASOURCE_PASSWORD: somepassword
SPRING_JPA_HIBERNATE_DDL_AUTO: create-drop
SPRING_PROFILES_ACTIVE: "prod"
# AWS EC2에 SSH 접속하여 NGINX 설치 및 실행
# - name: Install & Start NGINX
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.EC2_HOST }}
# username: ${{ secrets.EC2_USER }}
# key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
# script: |
# echo "Checking if NGINX is installed..."
# if ! command -v nginx &> /dev/null
# then
# echo "NGINX not found. Installing..."
# sudo apt update && sudo apt install -y nginx
# else
# echo "NGINX is already installed."
# fi
# echo "Starting NGINX..."
# sudo systemctl enable nginx
# sudo systemctl start nginx
# sudo systemctl status nginx
# NGINX 리버스 프록시 설정
# - name: Configure NGINX Reverse Proxy
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.EC2_HOST }}
# username: ${{ secrets.EC2_USER }}
# key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
# script: |
# echo "Setting up NGINX reverse proxy..."
# sudo bash -c 'cat > /etc/nginx/sites-available/default <<EOF
# server {
# listen 80;
# server_name _;
# location / {
# proxy_pass http://localhost:8080/;
# proxy_set_header Host \$host;
# proxy_set_header X-Real-IP \$remote_addr;
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto \$scheme;
# }
# }
# EOF'
# sudo nginx -t && sudo systemctl restart nginx
# 빌드된 JAR 파일을 EC2로 업로드
- name: Upload JAR to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
source: "build/libs/*-SNAPSHOT.jar"
target: "~/app/"
- name: Delete latest JAR file
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
cd ~/app
LATEST_JAR=$(ls -t *.jar | head -n 1) || true
echo "Latest JAR file: $LATEST_JAR"
for file in *.jar; do
if [[ "$file" != "$LATEST_JAR" ]]; then
echo "Deleting $file..."
rm -f "$file"
fi
done
continue-on-error: true
- name: Upload Dockerfile and Compose file
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
source: "deploy-Dockerfile, docker-compose.yaml"
target: "~"
- name: Deploy via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
echo "Starting containers..."
docker compose --env-file <(echo "
SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}
SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}
SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}
") up -d --no-deps myapp