git action cicd 구축 #10
Workflow file for this run
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: froxy Continuous Delivery | |
on: | |
push: | |
branches: | |
- release # release 브랜치에 푸시될 때 실행 | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-20.04 # 빌드가 진행될 환경 설정 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} # DockerHub 사용자 이름 | |
password: ${{ secrets.DOCKER_PASSWORD }} # DockerHub 비밀번호 | |
- name: Create .env file | |
run: | | |
echo "${{ secrets.BE_ENV }}" > .env | |
- name: Build Docker image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/froxy-server:latest . | |
- name: Push Docker image to Docker Hub | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/froxy-server:latest | |
- name: Setup SSH | |
uses: webfactory/ssh-agent@v0.5.3 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Deploy to server | |
run: | | |
ssh -o StrictHostKeyChecking=no mun@211.188.48.24 "docker pull docker-server:latest && \ | |
docker stop froxy-container || true && \ | |
docker rm froxy-container || true && \ | |
docker run -d --name froxy-container docker-server:latest}" # 서버에 Docker 이미지 다운로드 후 실행 |