Skip to content

Commit

Permalink
Added Docker (#89)
Browse files Browse the repository at this point in the history
* Add docker

* Added dev container

* Update docs

* Remove bash history from git

* Fix git in dev container

* Fix debug toolbar bug

* Improve docs

* Fix devcontainer envs

* Add more extensions to dev container

* Improve docs

* Attempt readme link fix

* Link fix didn't work :(

* Update docker compose file version

* Improve readme

* Fix formatting in contributing

* Remove old env

* fix mypy outside container

* Downgrade docker compose version

* Fix envs copy

* fix devcontainer

* Improve devcontainer usability

* Try fixing dev container

* fix frontend port forward in dev container

* try fix port forward again

* Fix badges and add codespace

* Improve readme

* Improve readme layout

* Correct logs commands

* Add more account info to readme

* Simplify envs

* Fix config

* Test code space automatic forwarding

* Prevent browser open when reading node logs

* Add healthcheck

* Dumb idea to fix port forwarding

* Didn't work :(

* Update readme

* Tslint (#91)

* added typescript-eslint

* updated code for eslint

* Added prettier

* Made docker container names consistent

* Added prettier to pre-commit

* Add node linting to ci

* Try fix typescript action

* Vote button (#92)

* Make running django outside docker easier

* Replace list of votes with number

* Add server action for vote

* Restructured lib/

* Added VoteButtons
  • Loading branch information
mfosterw authored Apr 11, 2024
1 parent cc42d1c commit d743a7b
Show file tree
Hide file tree
Showing 80 changed files with 2,123 additions and 463 deletions.
20 changes: 20 additions & 0 deletions .devcontainer/bashrc.override.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#
# .bashrc.override.sh
#

# persistent bash history
HISTFILE=~/.bash_history
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

# set some django env vars
source /entrypoint

# restore default shell options
set +o errexit
set +o pipefail
set +o nounset

# start ssh-agent
# https://code.visualstudio.com/docs/remote/troubleshooting
eval "$(ssh-agent -s)"
82 changes: 82 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// For format details, see https://containers.dev/implementors/json_reference/
{
"name": "democrasite_dev",
"dockerComposeFile": ["../docker-compose.local.yml"],
"init": true,
"mounts": [
{
"source": "./.devcontainer/bash_history",
"target": "/home/dev-user/.bash_history",
"type": "bind"
},
{
"source": "~/.ssh",
"target": "/home/dev-user/.ssh",
"type": "bind"
}
],
// Tells devcontainer.json supporting services / tools whether they should run
// /bin/sh -c "while sleep 1000; do :; done" when starting the container instead of the container’s default command
"overrideCommand": false,
"service": "django",
// Only run direct dependencies of the selected service
"runServices": ["node"],
// "remoteEnv": {"PATH": "/home/dev-user/.local/bin:${containerEnv:PATH}"},
"remoteUser": "dev-user",
"workspaceFolder": "/app",
"forwardPorts": [3000, 8000],
// Still holding out hope that one day autodiscovery will work in codespaces
"portsAttributes": {
"3000": {
"label": "Frontend"
},
"8000": {
"label": "Backend"
}
},
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
},
// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"settings": {
"editor.formatOnSave": true,
"[python]": {
"analysis.autoImportCompletions": true,
"analysis.typeCheckingMode": "basic",
"defaultInterpreterPath": "/usr/local/bin/python",
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
},
"editor.defaultFormatter": "charliermarsh.ruff",
"languageServer": "Pylance",
"linting.enabled": true,
"linting.mypyEnabled": true,
"linting.mypyPath": "/usr/local/bin/mypy"
}
},
// https://code.visualstudio.com/docs/remote/devcontainerjson-reference#_vs-code-specific-properties
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"davidanson.vscode-markdownlint",
"mrmlnc.vscode-duplicate",
"visualstudioexptteam.vscodeintellicode",
"visualstudioexptteam.intellicode-api-usage-examples",
// python
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"matangover.mypy",
// django
"batisteo.vscode-django",
"tamasfe.even-better-toml",
"trond-snekvik.simple-rst"
]
}
},
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",
"initializeCommand": "cp -rn .envs.template/ .envs/ || echo '.envs/ already exists'",
"postCreateCommand": "cat .devcontainer/bashrc.override.sh >> ~/.bashrc && git config --global --add safe.directory /app"
}
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.editorconfig
.gitattributes
.github
.gitignore
.gitlab-ci.yml
.idea
.pre-commit-config.yaml
.readthedocs.yml
.travis.yml
venv
.git
.envs/
9 changes: 0 additions & 9 deletions .env.sample

This file was deleted.

31 changes: 31 additions & 0 deletions .envs.template/.local/.django
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copy the .envs.template directory to .envs to provide custom configuration for
# docker-compose.local.yml. Don't forget to set the API keys in this file and .node if
# you want to use authentication

# General
# ------------------------------------------------------------------------------
USE_DOCKER=yes
IPYTHONDIR=/app/.ipython

# Redis
# ------------------------------------------------------------------------------
REDIS_URL=redis://redis:6379/0

# Celery
# ------------------------------------------------------------------------------

# Flower
CELERY_FLOWER_USER=user
CELERY_FLOWER_PASSWORD=password

# Social Auth
# ------------------------------------------------------------------------------
GOOGLE_CLIENT_ID=
GOOGLE_SECRET=
GITHUB_CLIENT_ID=
GITHUB_SECRET=

# Webiscite
# ------------------------------------------------------------------------------
GITHUB_WEBHOOK_SECRET=
GITHUB_TOKEN=
11 changes: 11 additions & 0 deletions .envs.template/.local/.node
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# democrasite-frontend/

# lib/api
# ------------------------------------------------------------------------------
BASE_API_URL=http://django:8000

# NextAuth
# ------------------------------------------------------------------------------
GITHUB_CLIENT_ID=
GITHUB_SECRET=
NEXTAUTH_SECRET=secret
7 changes: 7 additions & 0 deletions .envs.template/.local/.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# PostgreSQL
# ------------------------------------------------------------------------------
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=democrasite
POSTGRES_USER=user
POSTGRES_PASSWORD=password
91 changes: 85 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,96 @@
version: 2
updates:
# Update GitHub actions in workflows
- package-ecosystem: 'github-actions'
directory: '/'
- package-ecosystem: "github-actions"
directory: "/"
# Every weekday
schedule:
interval: 'daily'
interval: "daily"

# Enable version updates for Docker
# We need to specify each Dockerfile in a separate entry because Dependabot doesn't
# support wildcards or recursively checking subdirectories. Check this issue for updates:
# https://github.com/dependabot/dependabot-core/issues/2178
- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `compose/local/django` directory
directory: "compose/local/django/"
# Every weekday
schedule:
interval: "daily"
# Ignore minor version updates (3.10 -> 3.11) but update patch versions
ignore:
- dependency-name: "*"
update-types:
- "version-update:semver-major"
- "version-update:semver-minor"

- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `compose/local/docs` directory
directory: "compose/local/docs/"
# Every weekday
schedule:
interval: "daily"
# Ignore minor version updates (3.10 -> 3.11) but update patch versions
ignore:
- dependency-name: "*"
update-types:
- "version-update:semver-major"
- "version-update:semver-minor"

- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `compose/local/node` directory
directory: "compose/local/node/"
# Every weekday
schedule:
interval: "daily"

- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `compose/production/aws` directory
directory: "compose/production/aws/"
# Every weekday
schedule:
interval: "daily"

- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `compose/production/django` directory
directory: "compose/production/django/"
# Every weekday
schedule:
interval: "daily"
# Ignore minor version updates (3.10 -> 3.11) but update patch versions
ignore:
- dependency-name: "*"
update-types:
- "version-update:semver-major"
- "version-update:semver-minor"

- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `compose/production/postgres` directory
directory: "compose/production/postgres/"
# Every weekday
schedule:
interval: "daily"

- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `compose/production/traefik` directory
directory: "compose/production/traefik/"
# Every weekday
schedule:
interval: "daily"

# Enable version updates for Python/Pip - Production
- package-ecosystem: 'pip'
- package-ecosystem: "pip"
# Look for a `requirements.txt` in the `root` directory
# also 'setup.cfg', 'runtime.txt' and 'requirements/*.txt'
directory: '/'
directory: "/"
# Every weekday
schedule:
interval: "daily"

# Enable version updates for javascript/npm
- package-ecosystem: "npm"
# Look for a `packages.json` in the `root` directory
directory: "/democrasite-frontend/"
# Every weekday
schedule:
interval: 'daily'
interval: "daily"
70 changes: 35 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ concurrency:
cancel-in-progress: true

jobs:
linter:
# Doesn't require docker
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout Code Repository
Expand All @@ -29,51 +30,50 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.12"

# Consider using pre-commit.ci for open source project
- name: Run pre-commit
uses: pre-commit/[email protected]

# With no caching at all the entire ci process takes 4m 30s to complete!
pytest:
# Since these don't run from the root they are difficult to add to pre-commit
typescript:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./democrasite-frontend/
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "21.x"

- name: Install dependencies
run: npm ci

services:
redis:
image: redis:6
ports:
- 6379:6379
postgres:
image: postgres:15
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres

env:
CELERY_BROKER_URL: "redis://localhost:6379/0"
# postgres://user:password@host:port/database
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
- name: Run eslint and tsc
run: npm run lint

# With no caching at all the entire ci process takes 4m 30s to complete!
pytest:
runs-on: ubuntu-latest
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: |
requirements/base.txt
requirements/local.txt
- name: Copy environment files
run: cp -r .envs.template .envs

- name: Build the Stack
run: docker compose -f docker-compose.local.yml build django

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/local.txt
- name: Run DB Migrations
run: docker compose -f docker-compose.local.yml run --rm django python manage.py migrate

- name: Test with pytest and coverage
run: coverage run -m pytest
- name: Run Django Tests
run: docker compose -f docker-compose.local.yml run django pytest

- name: Send coverage report to codecov
uses: codecov/codecov-action@v3
- name: Tear down the Stack
run: docker compose -f docker-compose.local.yml down
Loading

0 comments on commit d743a7b

Please sign in to comment.