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

Streamline environment bootstrapping, move contents of docker/ to top level #510

Merged
merged 8 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
38 changes: 38 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is for settings that are specific to your local development
# environment

# Linux users may want to set these to their own UID and GID
# so that files created in the container will have the same permissions
# id -u and id -g may return the proper values
# This is unnecessary for Docker Desktop for Mac or Windows
# CTMS_UID=
# CTMS_GID=

# Docker
# Set this to always call docker-compose run with --service-ports in the Makefile
# MK_WITH_SERVICE_PORTS=--service-ports
# Set this to skip calling "docker-compose down" after "make tests"
# MK_KEEP_DOCKER_UP=1

# Logging
CTMS_USE_MOZLOG=False
CTMS_LOGGING_LEVEL=INFO
CTMS_LOG_SQLALCHEMY=False

# Change the webserver port
# PORT=8000

# Database
# The host for this URL is so that services running outside of docker
# (e.g. pytest) can use the database. It's overridden in docker-compose.yaml
# for use with `docker-compose up`
CTMS_DB_URL=postgresql://postgres@localhost:5432/postgres

# Encryption key for OAuth2 and other hashes
CTMS_SECRET_KEY=dev_only_secret_key_not_for_production

# Webserver protocol and domain
CTMS_SERVER_PREFIX=http://localhost:8000

# Reload server when files are changed
CTMS_APP_RELOAD=True
2 changes: 1 addition & 1 deletion .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
"$IMAGE_TAG" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./version.json
docker build --file docker/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker image tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: docker/Dockerfile
push: false
target: "production"
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}-test-build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.bash_history
.cache
.coverage
.DS_STORE
.env
.idea/
.mypy_cache/
Expand Down
11 changes: 1 addition & 10 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,6 @@
"line_number": 16
}
],
"docker/config/local_dev.env": [
{
"type": "Secret Keyword",
"filename": "docker/config/local_dev.env",
"hashed_secret": "9f33da7ed96322c0564596c334a5d7b3cc440621",
"is_verified": false,
"line_number": 7
}
],
"docs/developer_setup.md": [
{
"type": "Secret Keyword",
Expand Down Expand Up @@ -203,5 +194,5 @@
}
]
},
"generated_at": "2023-01-11T16:11:56Z"
"generated_at": "2023-01-13T18:46:50Z"
}
File renamed without changes.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ help:
.env:
@if [ ! -f .env ]; \
then \
echo "Copying env.dist to .env..."; \
cp docker/config/env.dist .env; \
echo "Copying .env.example to .env"; \
cp .env.example .env; \
grahamalama marked this conversation as resolved.
Show resolved Hide resolved
fi

install: $(INSTALL_STAMP)
Expand All @@ -47,7 +47,7 @@ build: .env
docker-compose build --build-arg userid=${CTMS_UID} --build-arg groupid=${CTMS_GID}

.PHONY: lint
lint: .env $(INSTALL_STAMP)
lint: $(INSTALL_STAMP)
bin/lint.sh

.PHONY: db-only
Expand Down
2 changes: 1 addition & 1 deletion bin/update_baseline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -euo pipefail

detect-secrets scan . \
poetry run detect-secrets scan . \
--baseline .secrets.baseline \
--exclude-files "(poetry.lock$)|(htmlcov/)"
7 changes: 3 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ services:
web:
build:
context: .
dockerfile: docker/Dockerfile
image: web
volumes:
- .:/app
Expand All @@ -12,9 +11,9 @@ services:
# Let the init system handle signals for us.
# among other things this helps shutdown be fast
init: true
env_file:
- docker/config/local_dev.env
- .env
environment:
CTMS_DB_URL: postgresql://postgres@postgres/postgres
env_file: .env
depends_on:
- postgres
postgres:
Expand Down
19 changes: 0 additions & 19 deletions docker/config/env.dist

This file was deleted.

14 changes: 0 additions & 14 deletions docker/config/local_dev.env

This file was deleted.

47 changes: 0 additions & 47 deletions docker/log_config.json

This file was deleted.

23 changes: 10 additions & 13 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,19 @@ instances and read by the CTMS API application for configuration. When
possible, the default values of environment variables are appropriate for
production.

In the local development environment, the default configuration is in
``docker/config/local_dev.env``, and overrides are in ``.env``. The file
``docker/config/env.dist`` is the ``.env`` template for new developer
In the local development environment, the default configuration is in ``.env``.
The file ``.env.example`` is the ``.env`` template for new developer
environments.

All configuration in ``.env`` is optional. Linux users should set
``CTMS_UID`` and ``CTMS_GID`` to match their user account, so that files
created inside the docker container have the same permissions as their user
account.

``.env`` is loaded in the ``Makefile``, making those configuration items
available in Makefile targets and commands. ``local_dev.env`` and ``.env``
are loaded by ``docker-compose`` and passed to Docker. Some adjust the build
process by setting `ARG` variables in the ``Dockerfile``. Others are passed
to the runtime environment. The CTMS API application then loads these from
the environment.
available in Makefile targets and commands. ``.env`` is also loaded by
``docker-compose`` and passed to Docker. Some adjust the build process by
setting `ARG` variables in the ``Dockerfile``. Others are passed to the runtime
environment. The CTMS API application then loads these from the environment.

Linux users should set ``CTMS_UID`` and ``CTMS_GID`` to match their user account,
so that files created inside the docker container have the same permissions as
their user account.

---
[View All Docs](./)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ profile = "black"
]

[tool.mypy]
# Sync Python version with docker/Dockerfile
# Sync Python version with Dockerfile
python_version = "3.10"
# Look for errors in this file
warn_unused_configs = true
Expand Down