Skip to content

Commit

Permalink
minimize(builder): scp build folder for serve
Browse files Browse the repository at this point in the history
  • Loading branch information
XHunter committed Dec 20, 2023
1 parent 173411b commit 26a6877
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
59 changes: 41 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
name: Build
name: Koders Portfolio App

on:
push:
branches: ["main"]
branches:
- main

jobs:
Deploy:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.13.2
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16.13.2
node-version: 16.14.0

- name: Install dependencies
run: npm install --production

- name: Build React app
run: npm run build

deploy:
runs-on: ubuntu-latest

needs: build

steps:
- name: Copy build to VPS via SSH
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
password: ${{ secrets.REMOTE_PASSWORD }}
source: "build/"
target: /root/portfolio/

- name: Cleaning remote docker image and container
uses: fifsky/ssh-action@master
continue-on-error: true
- name: SSH into VPS and deploy
uses: appleboy/ssh-action@master
with:
command: |
cd /root/portfolio/
git pull
docker build . -t koders-portfolio
docker rm $(docker stop $(docker ps -a -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio --format="{{.ID}}")) &&
docker rmi koders-portfolio
docker run -d -p 8080:80 --name koders-portfolio koders-portfolio
host: ${{ secrets.REMOTE_HOST }}
user: ${{ secrets.REMOTE_USER }}
pass: ${{ secrets.REMOTE_PASSWORD}}
username: ${{ secrets.REMOTE_USER }}
password: ${{ secrets.REMOTE_PASSWORD }}
script: |
cd /root/portfolio
docker rm $(docker stop $(docker ps -a -q --filter ancestor=koders-website-v5 --format="{{.ID}}"))
docker rmi koders-website-v5
docker build . -t koders-website-v5
docker run -d -p 8081:3000 --name koders-website-v5 -e ${{ secrets.WEBHOOK_URL }} koders-website-v5
30 changes: 20 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
FROM node:slim as build-stage
ENV NODE_OPTIONS=--openssl-legacy-provider
# Builder already added via Github Actions
# Uncomment for full workflow action
# FROM node:slim as build-stage
# ENV NODE_OPTIONS=--openssl-legacy-provider
# WORKDIR /app
# COPY package.json ./
# COPY package-lock.json ./
# COPY . .
# RUN npm ci --force
# RUN npm run build
# FROM nginx:stable-alpine
# COPY --from=build-stage /app/build/ /usr/share/nginx/html
# EXPOSE 80
# CMD ["nginx", "-g", "daemon off;"]

FROM node:16-slim
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY . .
RUN npm ci --force
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build-stage /app/build/ /usr/share/nginx/html
COPY build/ ./build/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
RUN npm install -g serve
CMD ["serve", "-s", "build", "-p", "80"]

0 comments on commit 26a6877

Please sign in to comment.