Skip to content

Commit

Permalink
First commit in public
Browse files Browse the repository at this point in the history
  • Loading branch information
jsga committed Oct 15, 2023
0 parents commit 06e4028
Show file tree
Hide file tree
Showing 81 changed files with 26,186 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/deploy-backend-from-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Development Integration

on:
push:
branches:
- main
# - deploy-k8

# Used for testing on a branch
# on: [pull_request]

env:
CLUSTER_NAME: avatar-cluster
NAMESPACE: backend-stripes
REGISTRY: avatar-registry
REPO_NAME: backend-stripes

jobs:
deploy:
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: climate
POSTGRES_USER: climate
POSTGRES_DB: climatedb
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2

- name: Install SOPS binary
uses: mdgreenwald/mozilla-sops-action@v1.1.0
with:
version: v3.7.3

- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Build container image
run: docker build -t registry.digitalocean.com/${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest --file backend/Dockerfile --target prod backend/

- name: Run lint
env:
DB_HOST: localhost
run: |
docker run registry.digitalocean.com/${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest flake8
- name: Run tests
env:
DB_HOST: localhost
run: |
docker run --network="host" registry.digitalocean.com/${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest pytest
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 1600

- name: Update Docker settings
run: |
sudo sed -i 's/ }/, \"max-concurrent-uploads\": 2 }/' /etc/docker/daemon.json
sudo systemctl restart docker
- name: Push image to DigitalOcean Container Registry
run: docker push registry.digitalocean.com/${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest

- name: Clean registry to save space, use only latest
run: yes | doctl registry garbage-collection start --include-untagged-manifests --force

- name: Save DigitalOcean kubeconfig with short-lived credentials
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{env.CLUSTER_NAME}}

- name: Define secrets in cluster
run: |
kubectl delete secret stripesbackendsecret --namespace ${{env.NAMESPACE}} --ignore-not-found
echo ${{secrets.SOPS_AGE_KEY_PRIVATE}} > keys_tmp.txt
export SOPS_AGE_KEY_FILE=$(pwd)/keys_tmp.txt
sops exec-file --input-type dotenv --output-type dotenv backend/prod.env.encrypted "kubectl create secret generic stripesbackendsecret --from-env-file={} --namespace=${{env.NAMESPACE}}"
- name: Deploy to DigitalOcean Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/backend/deploy/deployment_backend_api.yml

- name: Notify slack success
if: success()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: showyourlocalstripes-alerts
status: SUCCESS
color: good

- name: Notify slack fail
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: showyourlocalstripes-alerts
status: FAILED
color: danger
60 changes: 60 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: PR health check

on: [pull_request]

env:
CLUSTER_NAME: avatar-cluster
NAMESPACE: backend-stripes
REGISTRY: avatar-registry
REPO_NAME: backend-stripes

jobs:
deploy:
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: climate
POSTGRES_USER: climate
POSTGRES_DB: climatedb
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2

- name: Install SOPS binary
uses: mdgreenwald/mozilla-sops-action@v1.1.0
with:
version: v3.7.3

- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Build container image
run: docker build -t registry.digitalocean.com/${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest --file backend/Dockerfile --target prod backend/

- name: Run lint
env:
DB_HOST: localhost
run: |
docker run registry.digitalocean.com/${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest flake8
- name: Run tests
env:
DB_HOST: localhost
run: |
docker run --network="host" registry.digitalocean.com/${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest pytest
169 changes: 169 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Other
backend/data/ghcnm.tavg.v4.0.1.20230512.qfe.dat
**/*.DS_Store
backend/.prod.env
frontend/.prod.env
backend/.local.env
.devcontainer
.vscode
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
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.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# [#ShowYourLocalStripes 🟦⬜🟨🟧🟥](http://showyourlocalstripes.com/)

![showyourlocalstripes gif](preview.gif)

Front and backend of [https://showyourlocalstripes.com](https://showyourlocalstripes.com/).

- `backend/`: Python + FastAPI
- `frontend/`: Nuxt3 + TailwindCSS
- The physical handling of clothes is done by [Teemill](https://showyourlocalstripes.teemill.com/product/api-XeMwzpqq8rfiRE3lQpm861O0/)
- The frontend is deployed to a static page in Digital Ocean, and the Backend to a Kubernetes cluster.
- Postgres database with [CloudNativePg](https://github.com/cloudnative-pg/cloudnative-pg) Kubernetes operator
- PostHog for analytics
Loading

0 comments on commit 06e4028

Please sign in to comment.