Skip to content

Commit

Permalink
Launch migrations at boot
Browse files Browse the repository at this point in the history
  • Loading branch information
KenwoodFox committed Jan 11, 2025
1 parent b832dbc commit c9c660c
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 64 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore everything
*

# Don't ignore...
!battery/
!bin/
!log/
!manage.py
!README.md
!LICENSE
!requirements.txt

# Testing
!tests/
2 changes: 0 additions & 2 deletions .env

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ target/
__pycache__/
local_settings.py

# Dev
.env
db.sqlite3

# Dev DB
db.sqlite3
.local/
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ COPY . .
# Collect static files
RUN python manage.py collectstatic --noinput

# Bake in the git revision
ARG GIT_COMMIT
ENV GIT_COMMIT=$GIT_COMMIT

# Expose port
EXPOSE 8000

# Run the Django app
CMD ["./bin/entrypoint.sh"]
# Entrypoint
ENTRYPOINT "bin/entrypoint.sh"
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.PHONY: help

help: ## Prints this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

build: ## Build container locally
# Generate tag
echo TAG=$(shell git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9]/-/g') >> .env

# Build
docker-compose build --build-arg GIT_COMMIT=$(shell git describe --abbrev=8 --always --tags --dirty) --build-arg DEBUG=True

docker-rm: stop ## Delete container
docker-compose rm -f

shell: ## Get container shell
docker-compose run --entrypoint "/bin/bash" battery_server

run: build ## Run command in container
docker-compose run battery_server

stop: ## Stop container
docker-compose down
docker-compose stop

dev: ## Make everything you need to dev in the background
docker-compose -f docker-compose.yml up db pgadmin --remove-orphans

quick: build ## Make just what you need to quick-test
docker-compose -f docker-compose.yml up battery_server
59 changes: 0 additions & 59 deletions README

This file was deleted.

41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== battery.frc1721.org ===

https://battery.frc1721.org/

Django server to keep track of the state of batteries.
Made by dublu.

----- TODO

Sort and filter
Make it look better

## Development (using pipenv)

Use `pipenv` to manage python deps and versions

```shell
pipenv install
pipenv shell
```

Spawn a development django server

```shell
python manage.py migrate
python manage.py runserver
```

## Development (using docker)

In one terminal, start the `dev` requirements.

```shell
make dev
```

In another terminal, build and run a local copy of the server

```shell
make run
```
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Do not use for production!

services:
db:
image: postgres:10.5
restart: "no"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=battery_db
healthcheck:
test: ["CMD", "pg_isready", "-q", "-d", "battery_db", "-U", "postgres"]
interval: 10s
timeout: 5s
retries: 5
logging:
options:
max-size: 10m
max-file: "3"
ports:
- "5438:5432"
volumes:
- .local/data:/var/lib/postgresql/data

pgadmin:
image: dpage/pgadmin4
container_name: pgadmin4_container
restart: no
ports:
- "8888:80"
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: iamnotacrook
volumes:
- .local/pgadmin:/var/lib/pgadmin

battery_server:
depends_on:
db:
condition: service_healthy
build:
context: .
dockerfile: Dockerfile
environment:
LOG_LEVEL: "DEBUG"
restart: "no"
command: "true"

0 comments on commit c9c660c

Please sign in to comment.