Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create build-deploy-ec2.yml #546

Closed
wants to merge 10 commits into from
122 changes: 122 additions & 0 deletions .github/workflows/build-deploy-ec2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Build and Deploy to EC2
#on: workflow_dispatch
on: pull_request
jobs:
build-api:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./api
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
# - name: Install Python dependencies
# run: |
# python -m pip install --upgrade pip
# python -m pip install flake8 tox
# pip install -r requirements.txt
# pip install -r test-requirements.txt
# - name: Lint with flake8
# run: |
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with tox
# run: |
# tox
- name: Build API
run: |
python -m pip install build
python -m build --wheel
- name: Archive API
uses: actions/upload-artifact@v3
with:
name: api
path: api/dist
retention-days: 1
build-app:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./app
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# cache: 'npm'
- name: Run npm CI
run: npm ci
- name: Build app
run: npm run build
# - name: Test app
# run: npm run test
# - name: Run E2E tests
# uses: cypress-io/github-action@v5
# with:
# install: false
# start: npm run dev
# working-directory: ./app
# wait-on: http://localhost:4040
- name: Archive App
uses: actions/upload-artifact@v3
with:
name: app
path: app/dist
retention-days: 1
deploy-api-app:
needs: [build-api, build-app]
runs-on: ubuntu-latest
steps:
- name: Download all workflow run artifacts
uses: actions/download-artifact@v3
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.HUU_EC2_SSH_KEY }}
# The value below is the server's PUBLIC key. It's a required attribute for this action.
known_hosts: homeunite.us ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu/AdtdkNgDuezmkVeENDtC1Mf2erROKDEslMj+RFwuXj5CuLG2PRNTpzebgVlIJwxrq76+QWEFFG4gub2+mq2N+FlQ/if+R+a3Ym7lS3J25usgBliO6Dgp3Oxuq6n3V3/SopXIZ3/p8zGyBOiEjF8NXXy6y/ByfqT61jhZZR4MuMxdsaTbOI8wYfCAkxJTRn7E3U36iZNxgyxl5LCw97AxxiAzzg+f4GmpY7JuNy0EEqAEdRHPs6LBjrmDw6QLkDVS7AEA64yF8cDqDtNdB4Q/SkmJ0AyggU+fkFJ+wq01+mjtBMfjlaMmk+a2KowCIU6L+Mo2E7FnbQ0vKBg4iY3
- name: rsync over SSH API and App to EC2
run: |
# upload the api and app directories to the EC2 instance
rsync --mkpath -r app ubuntu@homeunite.us:github-deploy/
rsync --mkpath -r api ubuntu@homeunite.us:github-deploy/
- name: Configure EC2
uses: appleboy/ssh-action@v1.0.0
with:
host: homeunite.us
username: ubuntu
key: ${{ secrets.HUU_EC2_SSH_KEY }}
script_stop: true
# the following script was manually uploaded
# this will take at least 2 seconds to complete
script: |
cd /opt/homeuniteus
source homeuniteusenv/bin/activate
pip uninstall -y -r <(pip freeze)
pip install gunicorn
pip install ~/github-deploy/api/openapi_server-*.whl
deactivate
rm ~/github-deploy/api/*
sudo systemctl restart homeuniteus.service
cd ~/github-deploy/app
sudo rsync -a * /var/www/dev.homeunite.us/html/
rm -r *