Skip to content

Commit

Permalink
fixed docker node versions to support mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
kaxada committed Dec 15, 2023
1 parent fb218ce commit 26ad970
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 97 deletions.
182 changes: 86 additions & 96 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,4 @@
# name: CI/CD

# on:
# push:
# branches:
# - "*"
# pull_request:

# env:
# IMAGE_NAME: "project_badging"

# jobs:
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Install dependencies
# run: npm install
# - name: Lint code
# run: npm run format

# deploy:
# needs: build
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# steps:
# - uses: actions/checkout@v3
# - name: Build Docker image
# run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} .

# - name: Create image archive
# run: docker save ${{ env.IMAGE_NAME }}:${{ github.sha }} -o badging.tar

# - name: Upload image archive using appleboy/scp-action
# uses: appleboy/scp-action@v0.1.4
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# source: badging.tar
# target: ~/

# - name: Extract and load image on droplet
# uses: appleboy/ssh-action@v0.1.10
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# script: |
# if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then
# docker stop ${{ env.IMAGE_NAME }}
# docker rm ${{ env.IMAGE_NAME }}
# fi
# docker load -i ~/badging.tar
# docker run -d \
# -p ${{ secrets.PORT }}:${{ secrets.PORT }} \
# --env-file /home/${{ secrets.USERNAME }}/.env \
# --restart=always \
# --name ${{ env.IMAGE_NAME }} \
# ${{ env.IMAGE_NAME }}:${{ github.sha }}


name: Node.js CI/CD
name: CI/CD

on:
push:
Expand All @@ -69,57 +7,109 @@ on:
pull_request:

env:
DEPLOY_FOLDER: "project-badging-backend"
IMAGE_NAME: "project_badging"

jobs:
deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'

steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build Docker image
run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} .

- name: Cleanup existing content on the server
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
if [ -d ./${{ env.DEPLOY_FOLDER }} ]; then
cd ./${{ env.DEPLOY_FOLDER }}
find . -maxdepth 1 -type f ! -name '.env' -exec rm -f {} +
else
mkdir -p ./${{ env.DEPLOY_FOLDER }}
fi
- name: Create image archive
run: docker save ${{ env.IMAGE_NAME }}:${{ github.sha }} -o badging.tar

- name: Upload repository contents to the server
- name: Upload image archive using appleboy/scp-action
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: ./
target: ./${{ env.DEPLOY_FOLDER }}/
source: badging.tar
target: ~/

- name: Install npm dependencies on the server
- name: Extract and load image on droplet
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd ./${{ env.DEPLOY_FOLDER }}
npm install
if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then
docker stop ${{ env.IMAGE_NAME }}
docker rm ${{ env.IMAGE_NAME }}
fi
docker load -i ~/badging.tar
docker run -d \
-p ${{ secrets.PORT }}:${{ secrets.PORT }} \
--env-file /home/${{ secrets.USERNAME }}/.env \
--restart=always \
--name ${{ env.IMAGE_NAME }} \
${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Deploy with PM2
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd ./${{ env.DEPLOY_FOLDER }}
pm2 restart index.js
pm2 save --force
# name: Node.js CI/CD

# on:
# push:
# branches:
# - "*"
# pull_request:

# env:
# DEPLOY_FOLDER: "project-badging-backend"

# jobs:
# deploy:
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'

# steps:
# - name: Checkout repository
# uses: actions/checkout@v2

# - name: Cleanup existing content on the server
# uses: appleboy/ssh-action@v0.1.10
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# script: |
# if [ -d ./${{ env.DEPLOY_FOLDER }} ]; then
# cd ./${{ env.DEPLOY_FOLDER }}
# find . -maxdepth 1 -type f ! -name '.env' -exec rm -f {} +
# else
# mkdir -p ./${{ env.DEPLOY_FOLDER }}
# fi

# - name: Upload repository contents to the server
# uses: appleboy/scp-action@v0.1.4
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# source: ./
# target: ./${{ env.DEPLOY_FOLDER }}/

# - name: Install npm dependencies on the server
# uses: appleboy/ssh-action@v0.1.10
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# script: |
# cd ./${{ env.DEPLOY_FOLDER }}
# npm install

# - name: Deploy with PM2
# uses: appleboy/ssh-action@v0.1.10
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# script: |
# cd ./${{ env.DEPLOY_FOLDER }}
# pm2 restart index.js
# pm2 save --force
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:latest
FROM node:16
WORKDIR /app
COPY package*.json ./
RUN npm install
Expand Down

0 comments on commit 26ad970

Please sign in to comment.