Skip to content

Commit 6eabe3a

Browse files
authored
Merge pull request #165 from cmu-delphi/staging
Merge staging into main
2 parents 5ba2fc0 + 70655df commit 6eabe3a

File tree

815 files changed

+714082
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

815 files changed

+714082
-374
lines changed

.ci.env

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is used to allow CI to start the compose services. It will typcially
2+
# not need to be modified.
3+
4+
MYSQL_DATABASE=mysql_database
5+
MYSQL_USER=mysql_user
6+
MYSQL_PASSWORD=mysql_password
7+
MYSQL_PORT=3306
8+
MYSQL_ROOT_PASSWORD=test123!
9+
MYSQL_HOST=db
10+
11+
ALLOWED_HOSTS='127.0.0.1,localhost'
12+
CORS_ORIGIN_WHITELIST='http://127.0.0.1:3000,http://localhost:3000'
13+
CSRF_TRUSTED_ORIGINS='http://127.0.0.1:8000,http://localhost:8000'
14+
15+
SECRET_KEY='secret_key'
16+
DEBUG='True'
17+
18+
# Add the following to your local .env file. They will be used in the CI process
19+
# and you can largely forget about them, but including them in your .env file
20+
# will act like a safe default and help suppress warnings.
21+
REGISTRY=""
22+
TAG=""

.env.example

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
POSTGRES_DB=postgres_db_name
2-
POSTGRES_USER=postgres_db_user
3-
POSTGRES_PASSWORD=postgres_db_password
4-
POSTGRES_PORT=postgres_db_port
1+
MYSQL_DATABASE=mysql_database
2+
MYSQL_USER=mysql_user
3+
MYSQL_PASSWORD=mysql_password
4+
MYSQL_PORT=mysql_port
5+
MYSQL_HOST=mysql_host
6+
MYSQL_ROOT_PASSWORD=mysql_root_password
57

68
ALLOWED_HOSTS='127.0.0.1,localhost'
79
CORS_ORIGIN_WHITELIST='http://127.0.0.1:3000,http://localhost:3000'
810
CSRF_TRUSTED_ORIGINS='http://127.0.0.1:8000,http://localhost:8000'
911

1012
SECRET_KEY='secret_key'
1113
DEBUG='True'
14+
15+
# Sentry
16+
# Modify the Sentry config here. A DSN string is the minimum. Check the
17+
# application's Sentry init section and the Sentry documentation for the
18+
# defaults and options that may be set. If you don't want to use Sentry you can
19+
# leave this as is.
20+
#SENTRY_DSN=''
21+
22+
# Add the following to your local .env file. They will be used in the CI process
23+
# and you can largely forget about them, but including them in your .env file
24+
# will act like a safe default and help suppress warnings.
25+
REGISTRY=""
26+
TAG=""

.flake8

-9
This file was deleted.
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'Build and deploy application containers'
2+
on:
3+
push:
4+
jobs:
5+
build-tag-push-deploy:
6+
runs-on: ubuntu-latest
7+
# CI/CD will run on these branches
8+
if: >
9+
github.ref == 'refs/heads/main' ||
10+
github.ref == 'refs/heads/staging' ||
11+
github.ref == 'refs/heads/development'
12+
strategy:
13+
matrix:
14+
# Specify the docker-compose services to build images from
15+
service: [sdwebapp, sdnginx]
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: Login to GitHub container registry
20+
uses: docker/login-action@v1
21+
with:
22+
registry: ghcr.io
23+
username: cmu-delphi-deploy-machine
24+
password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
25+
- name: Create container image tags
26+
id: image-tag
27+
run: |
28+
baseRef="${GITHUB_REF#*/}"
29+
baseRef="${baseRef#*/}"
30+
case "${baseRef}" in
31+
main)
32+
image_tag="latest"
33+
;;
34+
*)
35+
image_tag="${baseRef//\//_}" # replace `/` with `_` in branch name
36+
;;
37+
esac
38+
echo "IMAGE_TAG=${image_tag}" >> $GITHUB_OUTPUT
39+
- name: Copy env file
40+
run: |
41+
cp ./.ci.env ./.env
42+
- name: Set up docker-compose
43+
uses: ndeloof/[email protected]
44+
- name: docker-compose build --push
45+
run: |
46+
docker-compose build --push ${{ matrix.service }}
47+
env:
48+
TAG: ":${{ steps.image-tag.outputs.IMAGE_TAG }}"
49+
REGISTRY: "ghcr.io/${{ github.repository_owner }}/"
50+
- name: docker-compose down
51+
run: |
52+
docker-compose down
53+
- name: Trigger smee.io webhook to pull new container images
54+
run: |
55+
curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \
56+
-X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \
57+
-H "Content-Type: application/x-www-form-urlencoded" \
58+
-d "repository=ghcr.io/${{ github.repository }}-${{ matrix.service }}&tag=${{ steps.image-tag.outputs.IMAGE_TAG }}"
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Update Sphinx Documentation
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
update-docs:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout source branch
15+
uses: actions/checkout@v3
16+
with:
17+
ref: ${{ github.event.pull_request.head.ref }}
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: '3.x'
24+
25+
- name: Install dependencies
26+
run: |
27+
python3 -m pip install --upgrade pip
28+
sudo apt-get update -y
29+
sudo apt-get install mysql-client -y
30+
sudo apt-get install graphviz graphviz-dev -y
31+
pip install pipenv
32+
pipenv requirements > requirements.txt
33+
pip install -r requirements.txt
34+
35+
36+
- name: Generate documentation
37+
run: |
38+
cd src/docs
39+
make clean
40+
make html
41+
42+
- name: setup git config
43+
run: |
44+
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
45+
git config user.name "GitHub Actions Bot"
46+
git config user.email "<>"
47+
48+
- name: Commit and push changes
49+
run: |
50+
git add -A
51+
git commit -m "Update Sphinx documentation"
52+
git push
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Sync GitHub issues to Jira
2+
on: [issues]
3+
4+
jobs:
5+
sync-issues:
6+
name: Sync issues to Jira
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Get the repository name
10+
id: repo_name
11+
run: echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_OUTPUT
12+
- name: Sync issues to Jira
13+
env:
14+
issue_id: ${{ github.event.issue.html_url }}
15+
issue_title: ${{ github.event.issue.title }}
16+
issue_body: ${{ github.event.issue.body }}
17+
issue_author: ${{ github.event.issue.user.login }}
18+
run: |
19+
# Add your action code here
20+
set -eux
21+
22+
if [ ${{ github.event_name }} != "issues" ]; then
23+
echo "This action only supports the issues event"
24+
exit 1
25+
fi
26+
if [ ${{ github.event.issue.pull_request }} ]; then
27+
echo "This action does not support pull requests"
28+
exit 0
29+
fi
30+
# Issue creation with label will trigger 2 events and run twice: one create, one labelled.
31+
# let just focus on labelling then for creating issues Jira-side.
32+
if [ ${{ github.event_name }} == "issues" ] && [ ${{ github.event.action }} == "opened" ]; then
33+
echo "Ignoring creation of issues as a label will trigger a second event."
34+
exit 0
35+
fi
36+
# We only operate on labelled issues or issues that are just unlabeled with our desired label which is 'jira'
37+
## check if one label of labels is our jira label
38+
toconsider=${{ contains(github.event.issue.labels.*.name, 'jira') }}
39+
if [ "${toconsider}" == false ]; then
40+
echo "Our desired label not found on issue or not unlabeled, skipping"
41+
exit 0
42+
fi
43+
# And finally, for the "labeled" event, we are only interested if the new added label is our desired one.
44+
if [ ${{ github.event.action }} == "labeled" ] && [ ${{ github.event.label.name }} != 'jira' ]; then
45+
echo "Not interested in this action, skipping"
46+
exit 0
47+
fi
48+
49+
# Convert markdown to JIRA using mistletoe package which is available starting with impish.
50+
# Since GH runners only have LTS versions it's safe to only check for focal which doesn't have the package.
51+
if [ $(lsb_release -c -s) == "focal" ]; then
52+
echo "Converting Markdown to JIRA is only possible starting with Ubuntu 22.04 (jammy). Pushing verbatim content to JIRA..."
53+
else
54+
TMPDIR=$(mktemp -d)
55+
trap 'rm -rf -- "$TMPDIR"' EXIT
56+
57+
sudo apt install -y python3-mistletoe
58+
echo ${issue_body} > $TMPDIR/body.md
59+
issue_body=$(PYTHONPATH=/usr/share/doc/python3-mistletoe mistletoe -r examples.jira_renderer.JIRARenderer $TMPDIR/body.md)
60+
fi
61+
62+
issue_description="*Issue created by ${issue_author}}*
63+
64+
Description: ${issue_body}
65+
66+
GitHub URL: ${issue_id}"
67+
# Choose Jira action based on event type and action
68+
action=""
69+
if [ ${{ github.event.action }} == "labeled" ]; then
70+
action=Create
71+
fi
72+
73+
echo "PUSHING: $issue_id $action $issue_title $issue_description"
74+
# Push to Jira as a json data format
75+
data=$(jq -n \
76+
--arg id "$issue_id" \
77+
--arg title "$issue_title" \
78+
--arg description "$issue_description" \
79+
--arg action "$action" \
80+
--arg project "${{ steps.repo_name.outputs.REPO_NAME }}" \
81+
'{data: {id: $id, title: $title, description: $description, action: $action, project: $project}}')
82+
curl -X POST -H "Content-Type: application/json" -d "${data}" '${{ secrets.JIRA_WEBHOOK }}'
83+
shell: bash
84+
85+
86+
87+
88+
89+
90+
91+
92+

.github/workflows/tests.yaml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Django Tests
2+
on: [pull_request, push]
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
8+
env:
9+
MYSQL_ROOT_PASSWORD: mysql_root_password
10+
MYSQL_DATABASE: mysql_database
11+
MYSQL_USER: mysql_user
12+
MYSQL_PASSWORD: mysql_password
13+
MYSQL_HOST: 127.0.0.1
14+
MYSQL_PORT: 3306
15+
16+
services:
17+
mysql:
18+
image: mysql:latest
19+
env:
20+
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
21+
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
22+
MYSQL_USER: ${{ env.MYSQL_USER }}
23+
MYSQL_PASSWORD: ${{ env.MYSQL_PASSWORD }}
24+
ports:
25+
- 3306:3306
26+
options: >-
27+
--health-cmd="mysqladmin ping"
28+
--health-interval=10s
29+
--health-timeout=5s
30+
--health-retries=3
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v2
35+
36+
- name: Set up Python
37+
uses: actions/setup-python@v2
38+
with:
39+
python-version: "3.10"
40+
41+
- name: Install dependencies
42+
run: |
43+
python3 -m pip install --upgrade pip
44+
sudo apt-get update -y
45+
sudo apt-get install mysql-client -y
46+
sudo apt-get install graphviz graphviz-dev -y
47+
pip install pipenv
48+
pipenv requirements > requirements.txt
49+
pip install -r requirements.txt
50+
51+
- name: Make migrations
52+
env:
53+
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
54+
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
55+
MYSQL_USER: ${{ env.MYSQL_USER }}
56+
MYSQL_PASSWORD: ${{ env.MYSQL_PASSWORD }}
57+
MYSQL_HOST: 127.0.0.1
58+
MYSQL_PORT: ${{ env.MYSQL_PORT }}
59+
60+
run: |
61+
mysql -u root -p"${{ env.MYSQL_ROOT_PASSWORD }}" -e "GRANT ALL PRIVILEGES ON *.* TO '${{ env.MYSQL_USER }}'@'%';"
62+
python3 ./src/manage.py migrate
63+
64+
- name: Run linters
65+
run: |
66+
pip install flake8
67+
flake8 .
68+
69+
- name: Run tests
70+
env:
71+
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
72+
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
73+
MYSQL_USER: ${{ env.MYSQL_USER }}
74+
MYSQL_PASSWORD: ${{ env.MYSQL_PASSWORD }}
75+
MYSQL_HOST: ${{ env.MYSQL_HOST }}
76+
MYSQL_PORT: ${{ env.MYSQL_PORT }}
77+
78+
run: |
79+
python3 ./src/manage.py test

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
.env
2+
.secrets
23
/.vscode/
34
/src/media/
4-
/src/static/
5+
/src/staticfiles/
6+
*log
57
*.mo
68
*.pyc
79
htmlcov/
810
.coverage
911
.coverage.*
1012
coverage.xml
1113
*.cover
14+
celerybeat-schedule.*

.isort.cfg

-5
This file was deleted.

0 commit comments

Comments
 (0)