Skip to content

Commit

Permalink
deploy (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
ostatni5 committed Nov 18, 2021
1 parent 625d7c2 commit f614206
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 33 deletions.
125 changes: 93 additions & 32 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,107 @@ env:
CI: false

jobs:
build:
# build_and_test:
# runs-on: ubuntu-latest

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
# strategy:
# matrix:
# node-version: [12.x, 14.x, 16.x]
# # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
# steps:
# - uses: actions/checkout@v2
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v2
# with:
# node-version: ${{ matrix.node-version }}
# cache: 'npm'
# - run: npm ci
# - run: npm run build --if-present
# - run: npm test

test_and_deploy:
# deploy_gh_pages:
# runs-on: ubuntu-latest
# needs: [build_and_test]
# steps:
# - name: Checkout 🛎️
# uses: actions/checkout@v2

# - name: Install 🔧
# run: npm install

# - name: webfactory/ssh-agent
# if: github.ref == 'refs/heads/master'
# uses: webfactory/ssh-agent@v0.5.3
# with:
# # Private SSH key to register in the SSH agent
# ssh-private-key: ${{ secrets.WEBDEV }}

# - name: Deploy
# if: github.ref == 'refs/heads/master'
# run: |
# git remote set-url origin git@github.com:yaptide/web_dev.git
# npm run deploy -- -u "github-actions-bot <support+actions@github.com>" -r "git@github.com:yaptide/web_dev.git"


deploy:
runs-on: ubuntu-latest
needs: [build]
needs: [build_and_test]
env:
FRONTEND_HOST: 149.156.182.181
FRONTEND_USER: ubuntu
if: github.ref == 'refs/heads/master'

steps:
- name: Checkout 🛎️
# Get the repo to the github agent
- name: Checkout
uses: actions/checkout@v2

- name: Install 🔧
run: npm install

- name: webfactory/ssh-agent
if: github.ref == 'refs/heads/master'
uses: webfactory/ssh-agent@v0.5.3
# Add keys to the SSH agent
- uses: webfactory/ssh-agent@v0.5.3

with:
# Private SSH key to register in the SSH agent
ssh-private-key: ${{ secrets.WEBDEV }}
ssh-private-key: |
${{ secrets.DEPLOY_C3_TEST }}
- name: Deploy
if: github.ref == 'refs/heads/master'
# Create the known_hosts file with the open stack machines public keys
- name: Add host to known_hosts
run: |
git remote set-url origin git@github.com:yaptide/web_dev.git
npm run deploy -- -u "github-actions-bot <support+actions@github.com>" -r "git@github.com:yaptide/web_dev.git"
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan -H ${{ env.FRONTEND_HOST }} >> ~/.ssh/known_hosts
# Kill docker container, then remove them
- name: Kill our docker container
continue-on-error: true
# if: github.ref == 'refs/heads/master'
uses: appleboy/ssh-action@master
with:
host: ${{ env.FRONTEND_HOST }}
username: ${{ env.FRONTEND_USER }}
key: ${{ secrets.DEPLOY_C3_TEST }}
script: |
docker rm --force yaptide-nginx
docker container prune --force

# Copy the new files form the github agent onto the machine
- name: Copy files to the machine
# if: github.ref == 'refs/heads/master'
run: rsync -a ~/work/ui/ui ${{ env.FRONTEND_USER }}@${{ env.FRONTEND_HOST }}:~/ui --exclude={node_modules,build}


- name: Build app and run docker container
# if: github.ref == 'refs/heads/master'
uses: appleboy/ssh-action@master
with:
host: ${{ env.FRONTEND_HOST }}
username: ${{ env.FRONTEND_USER }}
key: ${{ secrets.DEPLOY_C3_TEST }}
command_timeout: 10m
script: |
cd ui/ui
npm install
npm run build
docker run --name yaptide-nginx -p 8080:80 -v $PWD/build:/usr/share/nginx/html:ro -d nginx
4 changes: 3 additions & 1 deletion dockerRun.ps1
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
docker run --name some-nginx -p 8080:80 -v $pwd/build:/usr/share/nginx/html:ro -d nginx
ls $PWD/build
docker rm --force yaptide-nginx
docker run --name yaptide-nginx -p 8080:80 -v $PWD/build:/usr/share/nginx/html:ro -d nginx

0 comments on commit f614206

Please sign in to comment.