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

2024 docker fix #1400

Merged
merged 11 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"[python]": {
"editor.rulers": [120],
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
}
},
"[django-html]": {
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.3
FROM python:3.11.9

ARG DJANGO_ENV

Expand All @@ -9,7 +9,8 @@ ENV DJANGO_ENV=${DJANGO_ENV} \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.4.1
POETRY_VIRTUALENVS_CREATE=false \
POETRY_VERSION=1.8.3

# System deps:
RUN pip install "poetry==$POETRY_VERSION"
Expand All @@ -19,8 +20,7 @@ WORKDIR /app
COPY poetry.lock pyproject.toml /app/

# Project initialization:
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi
RUN poetry install --no-interaction --no-ansi

# Creating folders, and files for a project:
COPY . /app
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ We, the community and staff, have been building a custom Django application to h
## Initial Setup

1. Fork and clone this repository locally.
1. Download and install Docker for [Mac][docker-mac] or [Windows][docker-windows].
1. Create a new file names `.env` based on `.env.sample`.
1. Run the following to get a random Django secret key.
2. Download and install [OrbStack][orbstack] for Mac/Linux or [Docker for Windows][docker-windows].
3. Copy the `.env.sample` file to `.env`.

```sh
python -c "import secrets; print(secrets.token_urlsafe())"
```
```sh
cp .env.sample .env
```

4. Run the following to get a random Django secret key.

1. Enter the output inside the `.env` file for `SECRET_KEY`. Be sure to include the double quotes (`"`) around the key. It'll look like the following `SECRET_KEY="<unique-key-here>"`.
1. Navigate into the project directory via terminal and run `docker-compose build`
1. Once complete, run `docker-compose up`
1. Load up your browser and go to http://127.0.0.1:8000.
1. When you are done, you can stop the project via `ctrl+c`
```sh
python -c "import secrets; print(secrets.token_urlsafe())"
```

**Note:** Docker for Mac requires OSX Yosemite 10.10.3 or above. Docker for Windows requires Microsoft Windows 10 Professional, Enterprise 64-bit, Windows 10 Home (version 1903 or higher w/WSL 2). For previous versions download [Docker Toolbox][docker-toolbox].
5. Enter the output inside the `.env` file for `SECRET_KEY`. Be sure to include the double quotes (`"`) around the key. It'll look like the following `SECRET_KEY="<unique-key-here>"`.
6. Navigate into the project directory via terminal and run `docker compose up --build`
7. Load up your browser and go to http://127.0.0.1:8000.
8. When you are done, you can stop the project via `ctrl+c`

### Debugging Accounts

Expand All @@ -46,7 +48,7 @@ password: guardian

## Continual work

After the initial project setup, you will only need to run `docker-compose up --build`.
After the initial project setup, you will only need to run `docker compose up --build`.

## Useful Information

Expand All @@ -64,17 +66,17 @@ To grab the latest code from the main repo (named `upstream`), run the following

```console
git fetch upstream --prune
git checkout master
git merge upstream/master master
git checkout main
git merge upstream/main main
```

### Creating a new branch

Create a new branch based off of `upstream`'s `master` branch.
Create a new branch based off of `upstream`'s `main` branch.

```console
git fetch upstream --prune
git checkout -b feature/a-good-name upstream/master
git checkout -b feature/a-good-name upstream/main
git push -u origin feature/a-good-name
```

Expand All @@ -89,30 +91,31 @@ Follow the "Creating a new branch" step above. Be sure to always push to your `o
- Running a command on a Docker app in a new container.

```console
docker-compose run --rm app <command>
docker compose run --rm app <command>
```

Examples:

```console
docker-compose run --rm app /bin/bash
docker-compose run --rm app poetry lock
docker-compose run --rm app python manage.py makemigrations
docker-compose run --rm app python manage.py migrate
docker compose run --rm app /bin/bash
docker compose run --rm app poetry lock
docker compose run --rm app python manage.py makemigrations
docker compose run --rm app python manage.py migrate
```

- Cleaning up the docker containers:

```console
docker kill $(docker ps -q); docker-compose rm -f; docker volume rm $(docker volume ls -qf dangling=true);
docker kill $(docker ps -q); docker compose rm -f; docker volume rm $(docker volume ls -qf dangling=true);
```

- Rebuild docker containers after major changes:

```console
docker-compose build
docker compose build
```

[orbstack]: https://orbstack.dev/
[docker-mac]: https://www.docker.com/docker-mac
[docker-windows]: https://www.docker.com/docker-windows
[docker-toolbox]: https://www.docker.com/products/docker-toolbox
Expand Down
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"env": {
"POETRY_VERSION": {
"description": "Poetry Version",
"value": "1.4.1"
"value": "1.8.3"
},
"CONTACT_EMAIL": {
"required": true
Expand Down Expand Up @@ -53,7 +53,7 @@
"quantity": 1
}
},
"addons": ["heroku-postgresql", "logdna", "sendgrid"],
"addons": ["heroku-postgresql", "logdna"],
"buildpacks": [
{
"url": "https://github.com/moneymeets/python-poetry-buildpack.git"
Expand Down
4 changes: 2 additions & 2 deletions coderdojochi/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from django.utils.text import format_lazy

import html5.forms.widgets as html5_widgets
from captcha.fields import ReCaptchaField
from captcha.widgets import ReCaptchaV3
from django_recaptcha.fields import ReCaptchaField
from django_recaptcha.widgets import ReCaptchaV3
from dateutil.relativedelta import relativedelta

from coderdojochi.models import (
Expand Down
5 changes: 4 additions & 1 deletion coderdojochi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"import_export",
"django_nose",
"meta",
"captcha",
"django_recaptcha",
# apps
"accounts",
"coderdojochi",
Expand All @@ -122,6 +122,9 @@
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.contrib.redirects.middleware.RedirectFallbackMiddleware",

# Add the account middleware:
"allauth.account.middleware.AccountMiddleware",
]

ROOT_URLCONF = "coderdojochi.urls"
Expand Down
13 changes: 9 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
app:
restart: always
Expand All @@ -12,11 +10,18 @@ services:
ports:
- "8000:8000"
depends_on:
- db
db:
condition: service_healthy
restart: true
db:
image: postgres:15-alpine
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: mysecretpassword
container_name: dojo-v1-db
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -h localhost -U postgres"]
interval: 2s
timeout: 5s
retries: 15
12 changes: 6 additions & 6 deletions fixtures/14-coderdojochi.session.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created_at": "2000-01-01T06:00:00Z",
"updated_at": "2000-01-01T06:00:00Z",
"course": 1,
"start_date": "2023-01-01T16:00:00Z",
"start_date": "2025-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 1,
Expand Down Expand Up @@ -48,7 +48,7 @@
"created_at": "2000-01-01T06:00:00Z",
"updated_at": "2000-01-01T06:00:00Z",
"course": 1,
"start_date": "2023-02-02T16:00:00Z",
"start_date": "2025-02-02T16:00:00Z",
"location": 1,
"capacity": 20,
"mentor_capacity": 10,
Expand Down Expand Up @@ -90,7 +90,7 @@
"created_at": "2000-01-01T06:00:00Z",
"updated_at": "2000-01-01T06:00:00Z",
"course": 1,
"start_date": "2023-03-03T16:00:00Z",
"start_date": "2025-03-03T16:00:00Z",
"location": 2,
"capacity": 20,
"mentor_capacity": 10,
Expand Down Expand Up @@ -132,7 +132,7 @@
"created_at": "2000-01-01T06:00:00Z",
"updated_at": "2022-03-25T14:35:49.908Z",
"course": 1,
"start_date": "2023-04-04T15:00:00Z",
"start_date": "2025-04-04T15:00:00Z",
"location": 1,
"capacity": 20,
"mentor_capacity": 10,
Expand Down Expand Up @@ -174,7 +174,7 @@
"created_at": "2000-01-01T06:00:00Z",
"updated_at": "2000-01-01T06:00:00Z",
"course": 1,
"start_date": "2023-05-05T16:00:00Z",
"start_date": "2025-05-05T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
Expand Down Expand Up @@ -216,7 +216,7 @@
"created_at": "2000-01-01T06:00:00Z",
"updated_at": "2000-01-01T06:00:00Z",
"course": 2,
"start_date": "2023-07-06T15:00:00Z",
"start_date": "2025-07-06T15:00:00Z",
"location": 2,
"capacity": 20,
"mentor_capacity": 10,
Expand Down
Loading