π³ [CI/CD] deploy.yml μμ #75
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: Deploy | |
on: | |
push: | |
branches: [cicd/docker-deploy] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3.5.2 | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v2.5.2 | |
with: | |
node-version: lts/Hydrogen | |
- name: Cache node modules | |
uses: actions/cache@v2.1.8 | |
id: cache | |
with: | |
path: node_modules | |
key: npm-packages-${{ hashFiles('**/yarn.lock') }} | |
- name: Install Dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: yarn | |
- name: Build | |
run: yarn build | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/jmdb | |
- name: Pull and restart Docker Container | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.USER }} | |
script: | | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/jmdb | |
docker stop jmdb | |
docker run -d --rm --name jmdb -p 80:80 ${{ secrets.DOCKERHUB_USERNAME }}/jmdb |