Update README.md #20
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: Java CI and Deploy to AWS EC2 (Mock Docker Deployment) | |
on: | |
push: | |
branches: [ "readme" ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Save SSH key | |
env: | |
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }} | |
run: | | |
echo "$EC2_SSH_KEY" > ec2-key.pem | |
chmod 600 ec2-key.pem | |
- name: Upload source code to EC2 | |
env: | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_USER: ${{ secrets.EC2_USER }} | |
run: | | |
scp -i ec2-key.pem -o StrictHostKeyChecking=no -r ./* $EC2_USER@$EC2_HOST:/home/$EC2_USER/app | |
- name: Mock Build and Deploy on EC2 | |
env: | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_USER: ${{ secrets.EC2_USER }} | |
run: | | |
ssh -i ec2-key.pem -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << 'EOF' | |
MOCK=true | |
# λΉλ λ¨κ³ | |
if [ "$MOCK" = true ]; then | |
echo "EC2μμ μ ν리μΌμ΄μ λΉλ μ€..." | |
echo "./gradlew clean build -x test" | |
else | |
./gradlew clean build -x test | |
fi | |
# Docker μ΄λ―Έμ§ λΉλ λ¨κ³ | |
if [ "$MOCK" = true ]; then | |
echo "Docker μ΄λ―Έμ§λ₯Ό λΉλνλ μ€..." | |
echo "docker build -t care-app:latest ." | |
else | |
docker build -t care-app:latest . | |
fi | |
# κΈ°μ‘΄ 컨ν μ΄λ μ€μ§ λ° μμ | |
if [ "$MOCK" = true ]; then | |
echo "κΈ°μ‘΄ Docker 컨ν μ΄λ μ€μ§ λ° μμ μ€..." | |
echo "docker stop care-app-container || true" | |
echo "docker rm care-app-container || true" | |
else | |
docker stop care-app-container || true | |
docker rm care-app-container || true | |
fi | |
# μ Docker 컨ν μ΄λ μ€ν | |
if [ "$MOCK" = true ]; then | |
echo "μλ‘μ΄ Docker 컨ν μ΄λ μ€ν μ€..." | |
echo "docker run -d --name care-app-container -v /home/$EC2_USER/app/config/application-secret.yml:/app/config/application-secret.yml -p 8080:8080 care-app:latest" | |
else | |
docker run -d --name care-app-container -v /home/$EC2_USER/app/config/application-secret.yml:/app/config/application-secret.yml -p 8080:8080 care-app:latest | |
fi | |
echo "λ°°ν¬ μλ£" | |
EOF |