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

Merging in config settings for automatic prod deployment on fly.io #67

Merged
merged 18 commits into from
Jul 2, 2024
Merged
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
88 changes: 88 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# flyctl launch added from .gitignore
**/.env*
**/package-lock.json
**/.flaskenv
**/.DS_Store
**/node_modules
**/__pycache__
**/output-*
**/test.log
**/.firebaserc
**/emulator/2022-11-20T*
**/.idea/*
**/.vscode/*
**/venv
**/scripts/Nonprofit Tracking - Nonprofits.csv
**/scripts/nonprofits_round_3_from_pdf.csv
**/scripts/slagenciesfy1819.pdf
**/scripts/generated_image.png
**/test/data/*.xlsx

# flyctl launch added from emulator/.gitignore
# Logs
emulator/**/logs
emulator/**/*.log
emulator/**/npm-debug.log*
emulator/**/yarn-debug.log*
emulator/**/yarn-error.log*
emulator/**/firebase-debug.log*
emulator/**/firebase-debug.*.log*

# Firebase cache
emulator/**/.firebase

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
emulator/**/pids
emulator/**/*.pid
emulator/**/*.seed
emulator/**/*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
emulator/**/lib-cov

# Coverage directory used by tools like istanbul
emulator/**/coverage

# nyc test coverage
emulator/**/.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
emulator/**/.grunt

# Bower dependency directory (https://bower.io/)
emulator/**/bower_components

# node-waf configuration
emulator/**/.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
emulator/**/build/Release

# Dependency directories
emulator/**/node_modules

# Optional npm cache directory
emulator/**/.npm

# Optional eslint cache
emulator/**/.eslintcache

# Optional REPL history
emulator/**/.node_repl_history

# Output of 'npm pack'
emulator/**/*.tgz

# Yarn Integrity file
emulator/**/.yarn-integrity

# dotenv environment variables file
emulator/**/.env
fly.toml
23 changes: 23 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ENVIRONMENT=test
CLIENT_ORIGIN_URL=*


PROPEL_AUTH_KEY=AKEY


PROPEL_AUTH_URL=https://123456.propelauthtest.com


OPENAI_API_KEY=DISABLED
PORT=6060
FIREBASE_CERT_CONFIG={ "Something": "Something" }
FLASK_APP=api
FLASK_RUN_PORT=6060
FLASK_ENV=development

ENC_DEC_KEY="DISABLED"


SLACK_BOT_TOKEN=AKEYTODO
SLACK_WEBHOOK=WEBHOOKTHINGTODO

111 changes: 111 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: 🚀 Deploy
on:
push:
branches:
- develop
- main
pull_request: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
actions: write
contents: read

jobs:
lint:
name: ⬣ PYLint
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: 🐍 Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.9'

- name: 📥 Install dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

- name: 🔬 Lint
run: |
source venv/bin/activate
pylint -E api/*.py

tests:
name: 🧪 Tests
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: 🐍 Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.9'

- name: 📥 Install dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

- name: 🏄 Copy test env vars
run: cp .env.example .env

#- name: 🧪 Run tests
# run: |
# source venv/bin/activate
# pytest api/certificates/tests/test_always_pass.py

#- name: 📊 Upload test results
# uses: actions/upload-artifact@v3
# if: always()
# with:
# name: test-results
# path: ./test-results/
# retention-days: 30

deploy:
name: 🚀 Deploy
runs-on: ubuntu-latest
needs: [lint, tests]
# only build/deploy main branch on pushes
if:
${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') &&
github.event_name == 'push' }}

steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: 👀 Read app name
uses: SebRollen/[email protected]
id: app_name
with:
file: 'fly.toml'
field: 'app'

- name: 🚀 Deploy Dev to https://staging.yourapp.com/
if: ${{ github.ref == 'refs/heads/develop' }}
uses: superfly/[email protected]
with:
args:
'deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }}-staging'
env:
FLY_API_TOKEN: ${{ secrets.FLY_STAGING_API_TOKEN }}

- name: 🚀 Deploy Main to https://yourapp.com/
if: ${{ github.ref == 'refs/heads/main' }}
uses: superfly/[email protected]
with:
args:
'deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }}-prod'
env:
FLY_API_TOKEN: ${{ secrets.FLY_RELEASE_API_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.env*
.env
package-lock.json
.flaskenv
.DS_Store
Expand Down
15 changes: 15 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[MASTER]
init-hook='import sys; sys.path.append("./api")'
ignore=venv
extension-pkg-whitelist=flask

[MESSAGES CONTROL]
# Disable some of the Pylint messages
disable=
C0114, # missing-module-docstring
C0116, # missing-function-docstring
R0903, # too-few-public-methods

[REPORTS]
# Tweak the report output
reports=no
41 changes: 25 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
FROM python:3.9.2-slim-buster@sha256:721de1d0aea3331da282531b8b9e428d552b89bd6fd0d0c14e634deaddc241fc as build
RUN groupadd auth0 && useradd -m developer -g auth0
USER developer
WORKDIR /home/developer
COPY ./requirements.txt ./app/requirements.txt
RUN pip install --disable-pip-version-check -r ./app/requirements.txt --target ./packages
COPY ./api ./app/api
COPY ./common ./app/common
COPY ./gunicorn.conf.py ./app
FROM python:3.10-slim

FROM gcr.io/distroless/python3@sha256:eb773dd9d39f0becdab47e2ef5f1b10e2988c93a40ac8d32ca593096b409d351
COPY --from=build /home/developer/app /app
COPY --from=build /home/developer/packages /packages
USER 1000
EXPOSE 6060
ENV PYTHONPATH="/packages"
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app
CMD ["/packages/gunicorn/app/wsgiapp.py","api.wsgi:app"]

# Install git
RUN apt-get update && apt-get install -y git

# Install dependencies
COPY requirements.txt /app/
RUN python -m venv venv && \
. venv/bin/activate && \
pip install --no-cache-dir -r requirements.txt

EXPOSE 6060

# Bind to both IPv4 and IPv6
ENV GUNICORN_CMD_ARGS="--bind=[::]:6060 --workers=2"

# Copy project
COPY . /app/
# Run the application
CMD ["venv/bin/gunicorn", "api.wsgi:app", "--log-file=-", "--log-level", "debug", "--preload", "--workers", "1"]
15 changes: 15 additions & 0 deletions api/certificates/tests/test_always_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# tests/test_always_pass.py

import pytest
# Import env
import os
from dotenv import load_dotenv
load_dotenv()

def pytest_configure():
pytest.CERTIFICATE_TEST_REPO_URL: str = "https://github.com/whemminger/backend-ohack.dev.git"
pytest.CERTIFICATE_TEST_USERNAME: str = "Squibb"
pytest.CERTIFICATE_SAVE_DIR: str = "/tmp/"

def test_always_pass():
assert True
1 change: 1 addition & 0 deletions api/messages/messages_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def get_problem_statments():
def get_single_problem(project_id):
return (get_single_problem_statement_old(project_id))

#
# --------------------- TO BE REPLACED ROUTES ------------------------------------------#

# Used to provide profile details - user must be logged in
Expand Down
9 changes: 0 additions & 9 deletions docker-compose.yml

This file was deleted.

22 changes: 22 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# fly.toml app configuration file generated for backend-ohack-prod on 2024-07-01T15:53:09-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'backend-ohack'
primary_region = 'sjc'

[build]

[http_service]
internal_port = 6060
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 1
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ pytz==2023.4
propelauth_flask==2.1.11
littletable==2.2.4
et-xmlfile==1.1.0
openpyxl==3.1.2
openpyxl==3.1.2
pylint==3.2.5
pytest==8.2.2
1 change: 0 additions & 1 deletion services/nonprofits_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def get_npos():

def get_npo(id):
npo = fetch_npo(id)

return npo

@limits(calls=50, period=ONE_MINUTE)
Expand Down
Loading