From f6142066ff0bf2a0aa089b7c76f4252c916d96b2 Mon Sep 17 00:00:00 2001 From: ostatni5 <26521377+ostatni5@users.noreply.github.com> Date: Tue, 16 Nov 2021 16:22:57 +0100 Subject: [PATCH] deploy (#256) --- .github/workflows/node.js.yml | 125 +++++++++++++++++++++++++--------- dockerRun.ps1 | 4 +- 2 files changed, 96 insertions(+), 33 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index b3d08fd13..4a3e02d76 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -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 " -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 " -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 diff --git a/dockerRun.ps1 b/dockerRun.ps1 index d0f65822a..4ad115b26 100644 --- a/dockerRun.ps1 +++ b/dockerRun.ps1 @@ -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