feat: 기본 셋팅 #7
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: sarabwayu | |
on: | |
push: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Get current time | |
uses: josStorer/[email protected] | |
id: current-time | |
with: | |
format: YYYY-MM-DDTHH-mm-ss | |
utcOffset: "+09:00" | |
- uses: actions/checkout@v2 | |
- name: Docker build | |
run: | | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} | |
docker build -f Dockerfile -t taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} . | |
docker push taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.NCP_HOST }} | |
username: ${{ secrets.NCP_USER }} | |
password: ${{ secrets.NCP_PASSWORD }} | |
key: ${{ secrets.NCP_KEY }} | |
envs: GITHUB_SHA | |
script: | | |
sudo systemctl stop nginx || true | |
# Pull the new image | |
echo "🐳 Docker Image Pull" | |
sudo docker pull taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} | |
# Stop & Start | |
echo "🐳 Docker Stop & Start" | |
sudo docker stop docent-front | |
sudo docker run --rm -d --name docent-front -p 80:80 taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} | |
echo "▶️ Restarting Nginx service" | |
sudo systemctl start nginx || true | |
# Check | |
echo "🐳 Docker ps" | |
docker ps | |
# Cleanup old images | |
echo "🧹 Cleaning up old Docker images" | |
sudo docker rmi -f $(sudo docker images -q) || true |