Skip to content

git action cicd 구축 #12

git action cicd 구축

git action cicd 구축 #12

Workflow file for this run

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: Set Docker image tag as a variable
run: echo "DOCKER_TAG=${{ secrets.DOCKER_USERNAME }}/froxy-server:latest" >> $GITHUB_ENV
- name: Create .env file
run: |
echo "${{ secrets.BE_ENV }}" > .env
- name: Build Docker image
run: |
docker build -t $DOCKER_TAG .
- name: Push Docker image to Docker Hub
run: |
docker push $DOCKER_TAG
- 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 "sudo docker pull $DOCKER_TAG && \
docker stop froxy-container || true && \
docker rm froxy-container || true && \
docker run -d --name froxy-container $DOCKER_TAG}" # 서버에 Docker 이미지 다운로드 후 실행