Skip to content

123

123 #28

Workflow file for this run

name: CI
on:
push:
branches:
- main
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v3
- name: Build container image
run: docker build --no-cache -t kotatsu111/yumetune:backend .
- name: Log in Docker Hub
run: docker login -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Push image to Docker Hub
run: docker push kotatsu111/yumetune:backend
deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: build_and_push
steps:
- name: Deploy to VDS via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.VDS_HOST }}
username: root
password: ${{ secrets.VDS_PASSWORD }}
port: 22
script: |
# Login to Docker Hub
docker login -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWORD }}
# Stop running container
docker stop yumetune-backend-cont
# Remove old container
docker rm yumetune-backend-cont
# Remove old image
docker rmi kotatsu111/yumetune:backend
# Pull from Docker Hub
docker pull kotatsu111/yumetune:backend
# Run a new container from a new image
docker run -d --name yumetune-backend-cont -p 8000:8000 -e DATABASE_URL=${{ secrets.DATABASE_URL }} -e SECRET_KEY=${{ secrets.SECRET_KEY }} kotatsu111/yumetune:backend