#87 feat: redirect to home directory #25
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: Push Docker Image | |
on: | |
push: | |
branches: | |
- develop # 또는 배포하려는 브랜치 | |
- main | |
paths: | |
- '.github/workflows/web_serving.yml' | |
- 'Backend/web/**' | |
- 'Frontend/**' | |
env: | |
DOCKER_REGISTRY: khj4177 # Docker Hub 사용시 | |
IMAGE_NAME: gamepick2 # 이미지 이름 | |
IMAGE_TAG: latest # 이미지 태그 | |
DOCKERFILE_PATH: ./Backend/web # 빌드를 원하는 폴더 경로 | |
CONTAINER_NAME: web # 컨테이너 이름 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v2 | |
- | |
name: Copy Directory | |
run: | | |
cp -r ./Frontend ./Backend/web/ | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- | |
name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME_2 }} | |
password: ${{ secrets.DOCKERHUB_TOKEN_2 }} | |
- | |
name: Build and Push Docker Image | |
run: | | |
docker buildx create --use | |
docker buildx build -t $DOCKER_REGISTRY/$IMAGE_NAME:$IMAGE_TAG $DOCKERFILE_PATH --push | |
- | |
name: executing remote ssh commands using ssh key | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.WEB_HOST }} | |
username: ${{ secrets.WEB_USERNAME }} | |
key: ${{ secrets.WEB_SSH_KEY }} | |
port: 22 | |
envs: DOCKER_REGISTRY,IMAGE_NAME,IMAGE_TAG,CONTAINER_NAME | |
script: | | |
sudo docker pull $DOCKER_REGISTRY/$IMAGE_NAME:$IMAGE_TAG | |
sudo docker stop $CONTAINER_NAME | |
sudo docker rm $CONTAINER_NAME | |
sudo docker rmi $(docker images -f "dangling=true" -q) | |
sudo docker run --env-file .env -d --name $CONTAINER_NAME -p 80:8080 $DOCKER_REGISTRY/$IMAGE_NAME:$IMAGE_TAG |