Skip to content

Commit

Permalink
Modernizing tooling for future development (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni authored Oct 4, 2023
1 parent e2c0da9 commit 5a8b878
Show file tree
Hide file tree
Showing 51 changed files with 1,743 additions and 332 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use flake
export HKNWEB_MODE=dev
42 changes: 0 additions & 42 deletions .github/workflows/codeql.yml

This file was deleted.

95 changes: 95 additions & 0 deletions .github/workflows/test_and_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Test 🧪 and deploy 🚀

on:
push:
branches:
- "*"
pull_request:
branches: ["master"]

jobs:
test:
runs-on: ubuntu-latest
env:
HKNWEB_MODE: dev
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- uses: snok/install-poetry@v1
with:
version: 1.6.1
virtualenvs-create: true
virtualenvs-in-project: true
- uses: actions/cache@v3
with:
path: .venv
key: venv-${{ hashFiles('poetry.lock') }}

- run: poetry install --with prod --no-interaction --no-root

- name: Run formatting check
run: poetry run black . --check

- name: Run unit tests
run: |
poetry run coverage run
poetry run coverage report
- name: Deploy
run: |
poetry run fab deploy
- name: Run end-to-end tests
run: |
poetry run curl -f localhost:8000
deploy:
needs: test
runs-on: ubuntu-latest
if: success() && github.ref == 'refs/heads/master'
environment:
name: Production
url: https://dev-hkn.eecs.berkeley.edu/
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- uses: snok/install-poetry@v1
with:
version: 1.6.1
virtualenvs-create: true
virtualenvs-in-project: true
- uses: actions/cache@v3
with:
path: .venv
key: venv-${{ hashFiles('poetry.lock') }}

- run: poetry install --with prod --no-interaction --no-root

- name: Unseal secrets
uses: jrmcdonald/[email protected]
with:
bb_actions_subcommand: "postdeploy"
env:
BLACKBOX_PUBKEY: ${{ secrets.BLACKBOX_PUBLIC_KEY }}
BLACKBOX_PRIVKEY: ${{ secrets.BLACKBOX_PRIVATE_KEY }}

- name: Setup SSH key
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ~/.ssh/pkey
sudo chmod 600 ~/.ssh/pkey
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
shell: bash
env:
SSH_PRIVATE_KEY: ${{ secrets.OCF_SSH_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.OCF_SSH_KNOWN_HOSTS }}

- name: Deploy
run: |
poetry run fab deploy -i ~/.ssh/pkey --revision ${{ github.sha }}
env:
HKNWEB_MODE: ${{ vars.HKNWEB_MODE }}
24 changes: 0 additions & 24 deletions .github/workflows/test_deploy.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/test_formatting.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/test_logic_and_coverage.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# direnv
.direnv

# hknweb-specific stuff
.vagrant/
db.sqlite3
venv/
.venv/
media/

# Generic python stuff
Expand Down
Binary file modified bbtest.txt.gpg
Binary file not shown.
24 changes: 12 additions & 12 deletions config/deploy/github_actions.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"deploy": {
"name": "github_actions",
"user": "github_actions",
"host": "github_actions",
"conda_env": "hknweb-dev",
"run_blackbox_postdeploy": false,
"use_local_repo": true,
"path": {
"root": "/home/runner/work/hknweb"
},
"keep_releases": 1
}
"deploy": {
"name": "github_actions",
"user": "github_actions",
"host": "github_actions",
"run_blackbox_postdeploy": false,
"run_collectstatic": false,
"use_local_repo": true,
"path": {
"root": "/home/runner/work/hknweb"
},
"keep_releases": 1
}
}
24 changes: 12 additions & 12 deletions config/deploy/prod.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"deploy": {
"name": "prod",
"user": "hkn",
"host": "apphost.ocf.berkeley.edu",
"conda_env": "hknweb-prod",
"run_blackbox_postdeploy": true,
"use_local_repo": false,
"path": {
"root": "/home/h/hk/hkn/hknweb"
},
"keep_releases": 10
}
"deploy": {
"name": "prod",
"user": "hkn",
"host": "apphost.ocf.berkeley.edu",
"run_blackbox_postdeploy": true,
"run_collectstatic": true,
"use_local_repo": false,
"path": {
"root": "/home/h/hk/hkn/hknweb"
},
"keep_releases": 10
}
}
24 changes: 12 additions & 12 deletions config/deploy/shared.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"deploy": {
"path": {
"repo": "repo",
"releases": "releases",
"current": "current",
"shared": "shared"
},
"repo_url": "https://github.com/compserv/hknweb.git",
"branch": "master",
"linked_files": [],
"linked_dirs": []
}
"deploy": {
"path": {
"repo": "repo",
"releases": "releases",
"current": "current",
"shared": "shared"
},
"repo_url": "https://github.com/compserv/hknweb.git",
"branch": "master",
"linked_files": [],
"linked_dirs": []
}
}
13 changes: 0 additions & 13 deletions config/hknweb-dev.yml

This file was deleted.

11 changes: 0 additions & 11 deletions config/hknweb-prod.yml

This file was deleted.

13 changes: 0 additions & 13 deletions config/requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions config/systemd/hknweb.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Type=simple
Restart=always
PIDFile=/home/h/hk/hkn/hknweb/prod/current/gunicorn.pid
WorkingDirectory=/home/h/hk/hkn/hknweb/prod/current
Environment="HKNWEB_MODE=prod"
ExecStart=/home/h/hk/hkn/hknweb/prod/current/run
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
Loading

0 comments on commit 5a8b878

Please sign in to comment.