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

Add Fly.io to OHQ #258

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/shared-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,17 @@ jobs:

needs:
- publish-backend
- publish-frontend
- publish-frontend

flyctl-deploy:
name: "Flyctl Deploy"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: cd frontend && flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- run: cd backend && flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
55 changes: 2 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,2 @@
# Office Hours Queue

![Build and Deploy](https://github.com/pennlabs/office-hours-queue/workflows/Build%20and%20Deploy/badge.svg)
[![Coverage Status](https://codecov.io/gh/pennlabs/office-hours-queue/branch/master/graph/badge.svg)](https://codecov.io/gh/pennlabs/office-hours-queue)

This repo contains an office hour queue.

## Setting up your development environment

### Prerequisites
- Python 3.7 (`pyenv` is recommended)
- `pipenv`
- `docker` and `docker-compose`
- Node (>)10 (`nvm` is recommended)
- Yarn

### Launching the backend
Navigate to `/backend`. Then,

0. (Initial setup)
- a. `pipenv install --dev`
NOTE: You might have to install openssl with Homebrew (`brew install openssl`) and set the following environment variable for the linker.
`export LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib"`.<br>
If you run into `ERROR: Couldn't install package: psycopg2`, see [this](https://stackoverflow.com/questions/56796426/pipenv-consistently-failing-to-install-pyscopg2/57044429#57044429) post. If your problem is on M1, try the top 2 solutions [here](https://stackoverflow.com/questions/66888087/cannot-install-psycopg2-with-pip3-on-m1-mac).
- b. `pipenv shell`
1. `docker-compose up` (run this before doing any of the manage.py commands)
2. Migration commands to ensure your installation works:
- a. `python manage.py migrate`
- b. `python manage.py createsuperuser`
- c. `python manage.py populate` to populate the database with dummy data
- d. Ensure `python manage.py test` passes all tests.
- Note: to run a specific test, you can run `python manage.py test tests.ohq.test_file.TestCase`.
Note that you might have to run migrations or reinstall dependencies if the Pipfile or models have been changed upstream.

3. `python manage.py runserver 8000`
4. Documentation: [localhost:8000/api/documentation](http://localhost:8000/api/documentation)

### Launching the frontend
Navigate to `/frontend`. Then,

0. (Initial setup)
- a. `yarn install`
1. `yarn dev`

Finally, you should be able to authenticate at [localhost:8000/admin](http://localhost:8000/admin) and use the application at [localhost:3000](http://localhost:3000)! 🎉

### Integration testing
Users from the populate script all have password `pennlabs`.

0. Run manually
- a. Navigate to `/frontend`
- b. `yarn cypress open`
- c. Click on `question.spec.ts`
# fly-ohq
[Example] OHQ Deployed using Fly.io
42 changes: 42 additions & 0 deletions backend/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# fly.toml file generated for office-hours-queue-wsgi on 2023-03-19T12:30:29-04:00

app = "office-hours-queue-wsgi"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]
REDIS_URL = "redis://default:2a5b5896b6714c218ca8050b09d694ae@fly-office-hours-queue-redis.upstash.io"
# TODO: we need this to be fetched from fly
AWS_STORAGE_BUCKET_NAME = "ohq"
DJANGO_SETTINGS_MODULE = "ohq.settings.production"
GIT_SHA = "latest" # TODO: sus

[experimental]
auto_rollback = true

[[services]]
http_checks = []
internal_port = 80
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
39 changes: 39 additions & 0 deletions frontend/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# fly.toml file generated for office-hours-queue-react on 2023-02-07T01:27:04-05:00

app = "office-hours-queue-react"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]
DOMAIN = "office-hours-queue-react.fly.dev"
PORT = 3000

[experimental]
auto_rollback = true

[[services]]
http_checks = []
internal_port = 3000
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
56 changes: 3 additions & 53 deletions k8s/main.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,17 @@
import { Construct } from 'constructs';
import { App } from 'cdk8s';
import { CronJob, DjangoApplication, PennLabsChart, ReactApplication, RedisApplication } from '@pennlabs/kittyhawk';
import { CronJob, PennLabsChart } from '@pennlabs/kittyhawk';

const cronTime = require('cron-time-generator');

export class MyChart extends PennLabsChart {
constructor(scope: Construct) {
super(scope);

const frontendImage = 'pennlabs/office-hours-queue-frontend';
// const frontendImage = 'pennlabs/office-hours-queue-frontend';
const backendImage = 'pennlabs/office-hours-queue-backend';
const secret = 'office-hours-queue';
const domain = 'ohq.io';

new DjangoApplication(this, 'django-asgi', {
deployment: {
image: backendImage,
cmd: ['/usr/local/bin/asgi-run'],
replicas: 6,
secret,
env: [
{ name: 'REDIS_URL', value: 'redis://office-hours-queue-redis:6379' },
],
},
djangoSettingsModule: 'officehoursqueue.settings.production',
domains: [{ host: domain, paths: ['/api/ws'] }],
});

new DjangoApplication(this, 'django-wsgi', {
deployment: {
image: backendImage,
replicas: 8,
secret,
env: [
{ name: 'REDIS_URL', value: 'redis://office-hours-queue-redis:6379' },
],
},
djangoSettingsModule: 'officehoursqueue.settings.production',
domains: [{ host: domain, paths: ['/api', '/admin', '/assets'] }],
});

new ReactApplication(this, 'react', {
deployment: {
image: frontendImage,
replicas: 2,
},
domain: { host: domain, paths: ['/'] },
port: 80,
});

new RedisApplication(this, 'redis', {});

new DjangoApplication(this, 'celery', {
deployment: {
image: backendImage,
cmd: ['celery', '-A', 'officehoursqueue', 'worker', '-lINFO'],
secret,
env: [
{ name: 'REDIS_URL', value: 'redis://office-hours-queue-redis:6379' },
],
},
djangoSettingsModule: 'officehoursqueue.settings.production',
});
// const domain = 'ohq.io';

new CronJob(this, 'calculate-waits', {
schedule: cronTime.every(5).minutes(),
Expand Down
2 changes: 1 addition & 1 deletion k8s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"@pennlabs/kittyhawk": "^1.1.7",
"cdk8s": "^2.2.59",
"cdk8s": "^2.2.63",
"constructs": "^10.0.110"
},
"devDependencies": {
Expand Down
Loading