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

Part 1: infra changes #70

Open
wants to merge 4 commits into
base: backend+accounts+rankings
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
app/node_modules
app/npm-debug.log
app/build
node_modules
npm-debug.log
back/venv
20 changes: 20 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
NODE_LOCAL_PORT=2003
NODE_DOCKER_PORT=2003

FLASK_LOCAL_PORT=8083
FLASK_DOCKER_PORT=8083
FRONT_ADDRESS=http://localhost

REACT_APP_API_BASE_URL=http://localhost:8003

NODE_ENV=DEV
ENV=DEV

WCA_CLIENT_ID=example-id
WCA_CLIENT_SECRET=example-secret
WCA_HOST=https://staging.worldcubeassociation.org
SESSION_SECRET_KEY=12340987
DATASTORE_EMULATOR_HOST=localhost:8081
GOOGLE_CLOUD_PROJECT=scc-staging-391105

ADMIN_WCA_ID=2017ONDE01
29 changes: 29 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).

^(.*/)?#.*#$
^(.*/)?.*~$
^(.*/)?.*\.py[co]$
^(.*/)?\..*$
external/bootstrap
__pycache__/
/src/
/lib/
.git/
.gitignore
env/
back/venv/
app/node_modules/

# Ignore other unnecessary files
*.pyc
*.pyo
*.pyd
*.pyc
*.egg-info/
*.egg
*.bak
*.swp
*.DS_Store
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:16-alpine AS development
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, Node v20 would be preferred.

Additionally, is there a reason why you're using an Alpine image? Alpine can be the cause of many issues.

ENV NODE_ENV development

WORKDIR /
COPY app/package.json ./
COPY package-lock.json ./
RUN npm install

COPY . .
WORKDIR /app

CMD ["npm", "start"]
17 changes: 17 additions & 0 deletions app/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).

^(.*/)?#.*#$
^(.*/)?.*~$
^(.*/)?.*\.py[co]$
^(.*/)?\..*$
external/bootstrap
__pycache__/
/src/
/lib/
.git/
.gitignore
env/
venv/
12 changes: 12 additions & 0 deletions app/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
runtime: nodejs16
AlexandreOndet marked this conversation as resolved.
Show resolved Hide resolved

handlers:
# Serve all static files with url ending with a file extension
- url: /(.*\..+)$
static_files: build/\1
upload: build/(.*\..+)$

# Catch all handler to index.html
- url: /.*
static_files: build/index.html
upload: build/index.html
17 changes: 17 additions & 0 deletions back/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).

^(.*/)?#.*#$
^(.*/)?.*~$
^(.*/)?.*\.py[co]$
^(.*/)?\..*$
external/bootstrap
__pycache__/
/src/
/lib/
.git/
.gitignore
env/
venv/
12 changes: 12 additions & 0 deletions back/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
service: api
runtime: python311
entrypoint: gunicorn -b :$PORT backend:app

env_variables:
ENV: "PROD"
WCA_HOST: "https://staging.worldcubeassociation.org"

handlers:
- url: /.*
script: auto
secure: always
122 changes: 122 additions & 0 deletions back/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
indexes:
- kind: User
properties:
- name: wca_person
- name: name_lower
- name: name

- kind: User
properties:
- name: name_lower
- name: name

# AUTOGENERATED

# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

- kind: Champion
properties:
- name: event
- name: year
- name: region

- kind: Championship
properties:
- name: national_championship
- name: region
- name: year
direction: desc

- kind: Championship
properties:
- name: national_championship
- name: province
- name: year
direction: desc

- kind: Championship
properties:
- name: national_championship
- name: year
direction: desc

- kind: Championship
properties:
- name: region
- name: year
direction: desc

- kind: Championship
properties:
- name: province
- name: year
direction: desc

- kind: Championship
properties:
- name: year
- name: region

- kind: Competition
properties:
- name: country
- name: name

- kind: Competition
properties:
- name: year
- name: end_date

- kind: Competition
properties:
- name: year
- name: end_date
direction: desc

- kind: RankAverage
properties:
- name: event
- name: province
- name: best

- kind: RankSingle
properties:
- name: event
- name: province
- name: best

- kind: Result
properties:
- name: competition
- name: event
- name: round_type
- name: pos
direction: desc

- kind: Result
properties:
- name: competition
- name: pos

- kind: Result
properties:
- name: competition
- name: pos
direction: desc

- kind: UserLocationUpdate
properties:
- name: user
- name: update_time

- kind: UserLocationUpdate
properties:
- name: user
- name: update_time
direction: desc
134 changes: 134 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env bash
Copy link
Member

@JonEsparaz JonEsparaz Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason why this is a bash script?

I feel that a Python script would be more readable for most people. I would expect that the environment that this script will be run on (either CI or a developer's machine) would have Python install.


# Arguments:
# -p: deploy to prod
# -s: deploy to staging
# -f: frontend only
# -b: backend only
# -v <app version>: On staging, the name of the app version to upload.

set -e

PROJECT=""
IS_PROD=0
VERSION=""
FRONTEND_ONLY=0
BACKEND_ONLY=0

while getopts "psfbv:" opt; do
case $opt in
p)
PROJECT="scc-production-398617"
IS_PROD=1
;;
s)
PROJECT="scc-staging-391105"
IS_PROD=0
;;
f)
FRONTEND_ONLY=1
;;
b)
BACKEND_ONLY=1
;;
v)
VERSION="$OPTARG"
if [ "$VERSION" == "admin" ]
then
echo "You can't use -v admin. Please select another version name."
exit 1
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done


if [ -z "$PROJECT" ]
then
echo "Either -p (prod) or -s (staging) must be set." >&2
exit 1
fi

if [ $FRONTEND_ONLY -eq 1 ] && [ $BACKEND_ONLY -eq 1 ]
then
echo "Cannot set both -f (frontend only) and -b (backend only)." >&2
exit 1
fi

if [ "$IS_PROD" == "1" -a ! -z "$VERSION" ]
then
echo "You can't specify a version for the prod app." >&2
exit 1
fi

if [ "$IS_PROD" == "0" -a -z "$VERSION" ]
then
echo "You must specify a version with -v for the staging app." >&2
exit 1
fi

if [ $BACKEND_ONLY -eq 1 ]
then
echo "Deploying backend only."
CMD="gcloud app deploy back/api.yaml --project $PROJECT"
if [ ! -z "$VERSION" ]
then
CMD="$CMD --version $VERSION"
fi
echo "$CMD"
$CMD
exit 0
fi

echo "Recompiling react."
rm -rf app/build
cd app
if [ "$IS_PROD" == "0" ]
then
echo "Setting REACT_APP_API_BASE_URL to staging."
export REACT_APP_API_BASE_URL="https://api.staging.speedcubingcanada.org"
else
echo "Setting REACT_APP_API_BASE_URL to prod."
export REACT_APP_API_BASE_URL="https://api.speedcubingcanada.org"
fi
npm run build
cd ..

if [ $FRONTEND_ONLY -eq 1 ]
then
echo "Deploying frontend only."
CMD="gcloud app deploy app/app.yaml --project $PROJECT"
else
echo "Deploying to App Engine."
CMD="gcloud app deploy app/app.yaml dispatch.yaml back/api.yaml --project $PROJECT"
fi

if [ ! -z "$VERSION" ]
then
CMD="$CMD --version $VERSION"
fi

echo "$CMD"
$CMD

if [ ! -z "$VERSION" ]
then
URI="https://${VERSION}-dot-$PROJECT.appspot.com"
else
URI="https://$PROJECT.appspot.com"
fi
echo "Successfully uploaded to $URI."

if [ ! -z "$VERSION" ]
then
echo "Once you're done testing, please clean up by running:"
echo "gcloud app versions delete $VERSION --project $PROJECT"
fi
Loading