Skip to content

Commit

Permalink
Merge branch 'main' into feat/uuid-query-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Jul 25, 2024
2 parents 0418a61 + 30a39c1 commit 8364938
Show file tree
Hide file tree
Showing 399 changed files with 33,661 additions and 11,395 deletions.
84 changes: 57 additions & 27 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,69 @@
FROM python:3.9
FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.10@sha256:ef9cc483a593c95e1e83f2cf00b6a0e1ec7df43344416a41ccb3a88aef27beac

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG KUBENS_VERSION="0.9.4"
ARG OCTANT_VERSION="0.25.1"
ENV POETRY_VERSION="1.7.1"

# Install packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*

RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils 2>&1 \
&& apt-get -y install git openssh-client less iproute2 procps lsb-release libsodium-dev \
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get install -y sudo \
&& apt-get -y install curl unzip net-tools emacs fd-find exa \
&& apt-get -y install manpages man-db tldr \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& apt-get -y install --no-install-recommends \
apt-utils \
postgresql-client \
2>&1 \
&& apt-get -y install \
curl \
dnsutils \
emacs \
exa \
fd-find \
git \
iproute2 \
less \
libsodium-dev \
lsb-release \
man-db \
manpages \
net-tools \
nodejs \
npm \
openssh-client \
procps \
sudo \
tldr \
unzip \
vim \
libgtk2.0-0 \
libgtk-3-0 \
libgbm-dev \
libnotify-dev \
libgconf-2-4 \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
xauth \
xvfb \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

RUN curl -O -J -L https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/FiraMono.zip \
&& unzip FiraMono.zip -d ~/.fonts \
&& rm FiraMono.zip \
&& fc-cache -fv
# Upgrade pip
RUN pip install --upgrade pip

RUN curl -fsSL https://starship.rs/install.sh | bash -s -- -y
# Install kubens
RUN git clone -b v${KUBENS_VERSION} --single-branch https://github.com/ahmetb/kubectx /opt/kubectx \
&& ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx \
&& ln -s /opt/kubectx/kubens /usr/local/bin/kubens

COPY .devcontainer/scripts/notify-dev-entrypoint.sh /usr/local/bin/
# Install Octant
RUN curl -Lo octant.tar.gz https://github.com/vmware-tanzu/octant/releases/download/v${OCTANT_VERSION}/octant_${OCTANT_VERSION}_Linux-64bit.tar.gz \
&& tar -xvf octant.tar.gz \
&& mv octant_${OCTANT_VERSION}_Linux-64bit/octant /usr/local/bin/ \
&& rm -rf octant_${OCTANT_VERSION}_Linux-64bit

EXPOSE 8000
COPY .devcontainer/scripts/notify-dev-entrypoint.sh /usr/local/bin/

RUN python -m pip install wheel
ENV SHELL /bin/zsh

RUN echo "eval '$(starship init bash)'" >> /root/.bashrc
EXPOSE 8000
EXPOSE 6011
83 changes: 60 additions & 23 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,65 @@
{
"name": "Python 3.9 & PostgreSQL",
"name": "notification-api",
"dockerComposeFile": "docker-compose.yml",
"service": "dev",
"workspaceFolder": "/workspace",

"settings": {
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/usr/local/bin/pylint",
"python.pythonPath": "/usr/local/bin/python",
"terminal.integrated.shell.linux": "/bin/bash",
"terminal.integrated.fontFamily": "FiraCode Nerd Font Mono"
"shutdownAction": "stopCompose",
"remoteEnv": {
"PATH": "/home/vscode/.local/bin:${containerEnv:PATH}" // give our installed Python modules precedence
},

"extensions": [
"donjayamanne.python-extension-pack",
"ms-azuretools.vscode-docker",
"ms-python.vscode-pylance",
"eamodio.gitlens",
"wholroyd.jinja",
"pmbenjamin.vscode-snyk",
"visualstudioexptteam.vscodeintellicode",
"yzhang.markdown-all-in-one",
"ms-ossdata.vscode-postgresql",
"googlecloudtools.cloudcode"
]
}
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.formatOnSave": true
},
"python.formatting.blackPath": "/usr/local/bin/black",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/usr/local/bin/pylint",
"python.pythonPath": "/usr/local/bin/python"
},
"extensions": [
"bungcip.better-toml",
"donjayamanne.python-extension-pack",
"eamodio.gitlens",
"GitHub.copilot",
"GitHub.copilot-labs",
"googlecloudtools.cloudcode",
"kaiwood.center-editor-window",
"matangover.mypy",
"ms-azuretools.vscode-docker",
"ms-ossdata.vscode-postgresql",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vsliveshare.vsliveshare",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"pmbenjamin.vscode-snyk",
"timonwong.shellcheck",
"usernamehw.errorlens",
"visualstudioexptteam.vscodeintellicode",
"wenfangdu.jump",
"wholroyd.jinja",
"yzhang.markdown-all-in-one"
]
}
},
"features": {
"docker-from-docker": {
"version": "latest",
"moby": true
},
"kubectl-helm-minikube": {
"version": "latest",
"helm": "latest",
"minikube": "none"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "14.17.4"
}
},
"postCreateCommand": "notify-dev-entrypoint.sh",
"remoteUser": "vscode",

}
27 changes: 19 additions & 8 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ version: '3'

services:
dev:
build:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
entrypoint: notify-dev-entrypoint.sh
environment:
SQLALCHEMY_DATABASE_URI: postgresql://postgres:chummy@db/notification_api
SQLALCHEMY_DATABASE_TEST_URI: postgresql://postgres:chummy@db/test_notification_api
REDIS_URL: redis://redis:6380
volumes:
- ..:/workspace:cached
- ..:/workspace:cached
command: sleep infinity
ports:
ports:
- 8000:8000
- 8001:8001
links:
- 6011:6011
links:
- db

db:
image: postgres:11.2
image: postgres:11.22-bullseye@sha256:c886a3236b3d11abc302e64309186c90a69b49e53ccff23fd8c8b057b5b4bce9
volumes:
- ./initdb:/docker-entrypoint-initdb.d
- ./initdb:/docker-entrypoint-initdb.d
restart: always
command:
- "postgres"
Expand All @@ -31,6 +33,15 @@ services:
POSTGRES_PASSWORD: chummy
POSTGRES_HOST_AUTH_METHOD: trust
expose:
- "5432"
- "5432"
ports:
- "5432:5432"

redis:
image: redis:6.2@sha256:d4948d011cc38e94f0aafb8f9a60309bd93034e07d10e0767af534512cf012a9
restart: always
command: redis-server --port 6380
ports:
- "6380:6380"
expose:
- "6380"
72 changes: 45 additions & 27 deletions .devcontainer/scripts/notify-dev-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
#!/bin/bash
set -ex
set -ex

###################################################################
# This script will get executed *once* the Docker container has
# This script will get executed *once* the Docker container has
# been built. Commands that need to be executed with all available
# tools and the filesystem mount enabled should be located here.
# tools and the filesystem mount enabled should be located here.
###################################################################

# We want to enable broadcast message which by default is disabled.
sed '/mesg/d' ~/.profile > ~/.profile.bak && mv ~/.profile.bak ~/.profile
echo -e "\ntest -t 0 && mesg n" >> ~/.profile

# Define aliases
echo -e "\n\n# User's Aliases" >> ~/.profile
echo -e "alias fd=fdfind" >> ~/.profile
echo -e "alias l='ls -al --color'" >> ~/.profile
echo -e "alias ls='exa'" >> ~/.profile
echo -e "alias l='exa -alh'" >> ~/.profile
echo -e "alias ll='exa -alh@ --git'" >> ~/.profile
echo -e "alias lt='exa -al -T -L 2'" >> ~/.profile

cd /workspace

# Warm up git index prior to display status in prompt else it will
# be quite slow on every invocation of starship.
git status
echo -e "\n\n# User's Aliases" >> ~/.zshrc
echo -e "alias fd=fdfind" >> ~/.zshrc
echo -e "alias l='ls -al --color'" >> ~/.zshrc
echo -e "alias ls='exa'" >> ~/.zshrc
echo -e "alias l='exa -alh'" >> ~/.zshrc
echo -e "alias ll='exa -alh@ --git'" >> ~/.zshrc
echo -e "alias lt='exa -al -T -L 2'" >> ~/.zshrc

# Kubectl aliases and command autocomplete
echo -e "alias k='kubectl'" >> ~/.zshrc
echo -e "alias k-staging='aws eks --region ca-central-1 update-kubeconfig --name notification-canada-ca-staging-eks-cluster'" >> ~/.zshrc
echo -e "alias k-prod='aws eks --region ca-central-1 update-kubeconfig --name notification-canada-ca-production-eks-cluster'" >> ~/.zshrc
echo -e "source <(kubectl completion zsh)" >> ~/.zshrc
echo -e "complete -F __start_kubectl k" >> ~/.zshrc

# Smoke test
# requires adding files .env_staging and .env_prod to the root of the project
echo -e "alias smoke-local='cd /workspace && cp .env_smoke_local tests_smoke/.env && poetry run make smoke-test-local'" >> ~/.zshrc
echo -e "alias smoke-staging='cd /workspace && cp .env_smoke_staging tests_smoke/.env && poetry run make smoke-test'" >> ~/.zshrc
echo -e "alias smoke-prod='cd /workspace && cp .env_smoke_prod tests_smoke/.env && poetry run make smoke-test'" >> ~/.zshrc

cd /workspace

# Poetry autocomplete
echo -e "fpath+=/.zfunc" >> ~/.zshrc
echo -e "autoload -Uz compinit && compinit"

pip install poetry==${POETRY_VERSION}
export PATH=$PATH:/home/vscode/.local/bin/
which poetry
poetry --version

# Initialize poetry autocompletions
mkdir ~/.zfunc
touch ~/.zfunc/_poetry
poetry completions zsh > ~/.zfunc/_poetry

make generate-version-file
pip3 install -r requirements.txt
pip3 install -r requirements_for_test.txt

# Upgrade schema of the notification_api database.
flask db upgrade
# Install dependencies
poetry install

wall "The dev container entrypoint setup is complete!"
# Upgrade schema of the notification_api database.
poetry run flask db upgrade

# Bubble up the main Docker command to container.
exec "$@"
# install npm deps (i.e. cypress)
cd tests_cypress && npm install && npx cypress install && cd ..
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.env
8 changes: 8 additions & 0 deletions .env.devcontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
NOTIFY_ENVIRONMENT=development

REDIS_ENABLED="1"
REDIS_URL=redis://host.docker.internal:6380

FF_REDIS_BATCH_SAVING=true
FF_BATCH_INSERTION=true
FF_PRIORITY_LANES=true
Binary file removed .env.enc.aws
Binary file not shown.
14 changes: 8 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
NOTIFY_ENVIRONMENT=development

ADMIN_CLIENT_SECRET=dev-notify-secret-key
SRE_CLIENT_SECRET=dev-notify-secret-key
SECRET_KEY=dev-notify-secret-key
DANGEROUS_SALT=dev-notify-salt

MLWR_HOST=''
MLWR_USER=''
MLWR_KEY=''

SENDGRID_API_KEY=

NOTIFICATION_QUEUE_PREFIX='notification-canada-ca'

FLASK_APP=application.py
Expand All @@ -21,3 +16,10 @@ AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

AWS_PINPOINT_REGION=us-west-2
AWS_EMF_ENVIRONMENT=local

CONTACT_FORM_EMAIL_ADDRESS = ""

AWS_PINPOINT_SC_POOL_ID=
AWS_PINPOINT_SC_TEMPLATE_IDS=
AWS_PINPOINT_DEFAULT_POOL_ID=
Loading

0 comments on commit 8364938

Please sign in to comment.