Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: dockerize this repository and make sure that it can run on AWS
This involves a lot of small changes: - Add sentry support - Add GitHub Actions auto-deployment - Add Dockerfile - Patch werkzeug to only log non-2NN/3NN - Readme full of badges
- Loading branch information
Showing
15 changed files
with
307 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__pycache__/ | ||
*.pyc | ||
/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Deployment | ||
|
||
on: | ||
deployment: | ||
|
||
jobs: | ||
deploy_to_aws: | ||
name: Deploy to AWS | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Deployment in progress | ||
uses: openttd/actions/deployments-update@v1 | ||
with: | ||
github-token: ${{ secrets.DEPLOYMENT_TOKEN }} | ||
state: in_progress | ||
description: "Deployment of ${{ github.event.deployment.payload.version }} to ${{ github.event.deployment.environment }} started" | ||
|
||
- name: Deploy on AWS | ||
uses: openttd/actions/deploy-aws@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
name: BananasFrontendWeb | ||
|
||
- if: success() | ||
name: Deployment successful | ||
uses: openttd/actions/deployments-update@v1 | ||
with: | ||
github-token: ${{ secrets.DEPLOYMENT_TOKEN }} | ||
state: success | ||
description: "Successfully deployed ${{ github.event.deployment.payload.version }} on ${{ github.event.deployment.environment }}" | ||
url: "https://bananas.staging.openttd.org/" | ||
|
||
- if: failure() || cancelled() | ||
name: Deployment failed | ||
uses: openttd/actions/deployments-update@v1 | ||
with: | ||
github-token: ${{ secrets.DEPLOYMENT_TOKEN }} | ||
state: failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Publish image | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- '*' | ||
repository_dispatch: | ||
types: | ||
- publish_latest_tag | ||
- publish_master | ||
|
||
jobs: | ||
publish_image: | ||
name: Publish image | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- if: github.event_name == 'repository_dispatch' | ||
name: Repository dispatch | ||
uses: openttd/actions/checkout-dispatch@v1 | ||
|
||
- name: Checkout tags and submodules | ||
uses: openttd/actions/checkout@v1 | ||
with: | ||
with-tags: true | ||
|
||
- name: Set variables | ||
id: vars | ||
uses: openttd/actions/docker-vars@v1 | ||
with: | ||
docker-hub-username: ${{ secrets.DOCKER_USERNAME }} | ||
|
||
- name: Build | ||
uses: openttd/actions/docker-build@v1 | ||
with: | ||
name: ${{ steps.vars.outputs.name }} | ||
tag: ${{ steps.vars.outputs.tag }} | ||
tags: ${{ steps.vars.outputs.tags }} | ||
version: ${{ steps.vars.outputs.version }} | ||
date: ${{ steps.vars.outputs.date }} | ||
|
||
- if: steps.vars.outputs.dry-run == 'false' | ||
name: Publish | ||
id: publish | ||
uses: openttd/actions/docker-publish@v1 | ||
with: | ||
docker-hub-username: ${{ secrets.DOCKER_USERNAME }} | ||
docker-hub-password: ${{ secrets.DOCKER_PASSWORD }} | ||
name: ${{ steps.vars.outputs.name }} | ||
tag: ${{ steps.vars.outputs.tag }} | ||
|
||
- if: steps.vars.outputs.dry-run == 'false' | ||
name: Trigger deployment | ||
uses: openttd/actions/deployments-create@v1 | ||
with: | ||
ref: ${{ steps.vars.outputs.sha }} | ||
environment: ${{ steps.vars.outputs.environment }} | ||
version: ${{ steps.vars.outputs.version }} | ||
date: ${{ steps.vars.outputs.date }} | ||
docker-tag: ${{ steps.publish.outputs.remote-tag }} | ||
github-token: ${{ secrets.DEPLOYMENT_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM python:3.8-slim | ||
|
||
ARG BUILD_DATE="" | ||
ARG BUILD_VERSION="dev" | ||
|
||
LABEL maintainer="truebrain@openttd.org" | ||
LABEL org.label-schema.schema-version="1.0" | ||
LABEL org.label-schema.build-date=${BUILD_DATE} | ||
LABEL org.label-schema.version=${BUILD_VERSION} | ||
|
||
WORKDIR /code | ||
|
||
COPY requirements.txt \ | ||
LICENSE \ | ||
README.md \ | ||
.version \ | ||
/code/ | ||
# Needed for Sentry to know what version we are running | ||
RUN echo "${BUILD_VERSION}" > /code/.version | ||
|
||
RUN pip --no-cache-dir install -r requirements.txt | ||
|
||
# Validate that what was installed was what was expected | ||
RUN pip freeze 2>/dev/null > requirements.installed \ | ||
&& diff -u --strip-trailing-cr requirements.txt requirements.installed 1>&2 \ | ||
|| ( echo "!! ERROR !! requirements.txt defined different packages or versions for installation" \ | ||
&& exit 1 ) 1>&2 | ||
|
||
COPY webclient /code/webclient | ||
|
||
ENTRYPOINT ["python", "-m", "webclient"] | ||
CMD ["--authentication-method", "developer", "--developer-username", "developer", "--api-url", "http://127.0.0.1:8080", "--frontend-url", "https://127.0.0.1:5000", "run", "-p", "80", "-h", "0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Flask | ||
requests | ||
sentry_sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
def click_additional_options(additional_func): | ||
def decorator(func): | ||
additional_params = [] | ||
for param in getattr(additional_func, "__click_params__", []): | ||
additional_params.append(param.name) | ||
|
||
def inner_decorator(**kwargs): | ||
additional_kwargs = {param: kwargs[param] for param in additional_params} | ||
additional_func(**additional_kwargs) | ||
|
||
# Remove the kwargs that are consumed by the additional_func | ||
[kwargs.pop(kwarg) for kwarg in additional_kwargs] | ||
|
||
func(**kwargs) | ||
|
||
inner_decorator.__click_params__ = getattr(func, "__click_params__", []) + getattr( | ||
additional_func, "__click_params__", [] | ||
) | ||
inner_decorator.__doc__ = func.__doc__ | ||
return inner_decorator | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import click | ||
import logging | ||
import sentry_sdk | ||
|
||
from .click import click_additional_options | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@click_additional_options | ||
@click.option("--sentry-dsn", help="Sentry DSN.") | ||
@click.option( | ||
"--sentry-environment", help="Environment we are running in.", default="development", | ||
) | ||
def click_sentry(sentry_dsn, sentry_environment): | ||
if not sentry_dsn: | ||
return | ||
|
||
# Release is expected to be in the file '.version' | ||
with open(".version") as f: | ||
release = f.readline().strip() | ||
|
||
sentry_sdk.init(sentry_dsn, release=release, environment=sentry_environment) | ||
log.info( | ||
"Sentry initialized with release='%s' and environment='%s'", release, sentry_environment, | ||
) |
Oops, something went wrong.