Skip to content

Commit

Permalink
Merge pull request #53 from co-cddo/simplify-docker-compose
Browse files Browse the repository at this point in the history
Simplify Docker and Docker Compose files
  • Loading branch information
jimnarey authored Mar 12, 2024
2 parents a4f6110 + c21634c commit 189c856
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 47 deletions.
28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ FROM public.ecr.aws/docker/library/python:3.10

ARG POETRY_ARGS="--no-root --no-ansi --only main"

WORKDIR /srv/request_a_govuk_domain
RUN useradd -u 1000 govuk_domain

RUN pip install poetry gunicorn \
&& useradd -u 1000 govuk_domain
RUN pip install poetry gunicorn

COPY pyproject.toml poetry.lock /srv/request_a_govuk_domain/
COPY pyproject.toml poetry.lock /app/

RUN poetry config virtualenvs.create false \
&& poetry install ${POETRY_ARGS}
WORKDIR /app

COPY manage.py /srv/request_a_govuk_domain/
COPY request_a_govuk_domain /srv/request_a_govuk_domain/request_a_govuk_domain
RUN poetry config virtualenvs.create false && \
poetry install ${POETRY_ARGS}

RUN sed -i 's/\r$//' /srv/request_a_govuk_domain/manage.py && \
chmod +x /srv/request_a_govuk_domain/manage.py
COPY manage.py /app/
COPY request_a_govuk_domain /app/request_a_govuk_domain

RUN SECRET_KEY=unneeded /srv/request_a_govuk_domain/manage.py collectstatic --no-input
RUN sed -i 's/\r$//' /app/manage.py && \
chmod +x /app/manage.py

RUN mkdir /var/run/request_a_govuk_domain \
&& chown govuk_domain:govuk_domain /var/run/request_a_govuk_domain
RUN SECRET_KEY=unneeded /app/manage.py collectstatic --no-input

RUN mkdir /var/run/request_a_govuk_domain && \
chown govuk_domain:govuk_domain /var/run/request_a_govuk_domain

RUN mkdir /home/govuk_domain && \
chown govuk_domain:govuk_domain /home/govuk_domain

USER govuk_domain


EXPOSE 8000
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,21 @@ Steps to run the project locally on docker:
1. Clone the repository
2. Go to the project directory: domains-register-a-govuk-domain
3. Ensure docker is running on your machine
4. Run the following command to run the application:
```bash
make collectstatic; make up
```

The command `make collectstatic` is to collect the static files and `make up` is to run the application on docker.

`make collectstatic` is a one-time command to collect the static files. It is not required to run this command every time, unless there are changes in the static files.

So after the first time, the command to run the application on local docker is:
```bash
make up
```

Alternatively, you can use `make up-devserver` to use the Django development server in place of gunicorn.

When the application is run, any migrations are applied to the database. Seed data for the `reviewer` user group (see below) is also applied.

Just run either `make up` or `make up-devserver` again.
4. Run one of the following commands to run the application:

- Using gunicorn:
```bash
make up
```
- Using the Django development server:
```bash
make up-devserver
```

When the application is run:
- Any migrations are applied to the database.
- Static files collected.
- Seed data (see below) is also applied if it doesn't already exist.
## Usage instructions
Expand Down
5 changes: 0 additions & 5 deletions docker-compose-local.yml

This file was deleted.

14 changes: 5 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ x-api-base: &api-base
args:
POETRY_ARGS: "--no-root --no-ansi"
volumes:
- .:/srv/request_a_govuk_domain
- .:/app

services:

web:
platform: linux/amd64
build:
context: .
args:
POETRY_ARGS: "--no-root --no-ansi"
volumes:
- ./request_a_govuk_domain:/srv/request_a_govuk_domain/request_a_govuk_domain
- govuk_domain_home:/home/govuk_domain
<<: *api-base
ports:
- "8000:8000"
#Added the reload flag so the application will be reloaded when the source is modified.
Expand All @@ -33,6 +27,8 @@ services:
depends_on:
postgres:
condition: service_healthy
init:
condition: service_completed_successfully

postgres:
platform: linux/amd64
Expand All @@ -57,7 +53,7 @@ services:
restart: 'no'
environment:
<<: *common-application-variables
command: [ "sh", "-c", "python manage.py migrate --noinput && python manage.py loaddata ./seed/reviewer_group.json ./seed/users.json ./seed/request.json" ]
command: [ "sh", "/app/local-init.sh" ]
depends_on:
postgres:
condition: service_healthy
Expand Down

0 comments on commit 189c856

Please sign in to comment.