Skip to content

Commit

Permalink
Option pour lancer le projet avec Docker (#4574)
Browse files Browse the repository at this point in the history
Co-authored-by: Stéphane Maniaci <[email protected]>
  • Loading branch information
hfroot and freesteph authored Oct 30, 2024
1 parent a3a417f commit ed4a13d
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 139 deletions.
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.DS_Store
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
48 changes: 48 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ALLOWED_HOSTS=localhost
SECRET=my local secret
DEBUG=True
DEBUG_FRONT=True
DB_USER=postgres
DB_PASSWORD=password
DB_HOST=db
DB_PORT=3306
DB_NAME=ma-cantine
HOSTNAME=localhost:8000
STATICFILES_STORAGE=django.contrib.staticfiles.storage.StaticFilesStorage
DEFAULT_FILE_STORAGE=django.core.files.storage.FileSystemStorage
EMAIL_BACKEND=anymail.backends.sendinblue.EmailBackend
[email protected]
[email protected]
SENDINBLUE_API_KEY=
NEWSLETTER_SENDINBLUE_LIST_ID=
MATOMO_ID=
CELLAR_HOST=
CELLAR_KEY=
CELLAR_SECRET=
CELLAR_BUCKET_NAME=
DATA_WARE_HOUSE_USER=
DATA_WARE_HOUSE_PASSWORD=
DATA_WARE_HOUSE_HOST=
DATA_WARE_HOUSE_PORT=
DATA_WARE_HOUSE_DB=
DEBUG_PERFORMANCE=True
ENVIRONMENT=dev
REDIS_URL=redis://localhost:6379/0
REDIS_PREPEND_KEY=LOCAL
OVERRIDE_TEST_SEED=
SIRET_API_KEY=
SIRET_API_SECRET=
MONCOMPTEPRO_CLIENT_ID=
MONCOMPTEPRO_SECRET=
MONCOMPTEPRO_CONFIG=
MAX_DAYS_HISTORICAL_RECORDS=
CSV_PURCHASE_CHUNK_LINES=
ENABLE_XP_RESERVATION=True
ENABLE_XP_VEGE=True
ENABLE_TELEDECLARATION=False
TELEDECLARATION_CORRECTION_CAMPAIGN=False
TELEDECLARATION_END_DATE=2024-05-01
ENABLE_DASHBOARD=True
PUBLISH_BY_DEFAULT=True
ENABLE_VUE3=True
ENABLE_WASTE_MEASUREMENTS=True
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ ENV/
env.bak/
venv.bak/

# local env files
.env.local
.env.*.local

# Spyder project settings
.spyderproject
.spyproject
Expand All @@ -128,10 +132,6 @@ venv.bak/
frontend/node_modules
frontend/dist

# local env files
frontend/.env.local
frontend/.env.*.local

# Log files
frontend/npm-debug.log*
frontend/yarn-debug.log*
Expand All @@ -145,6 +145,7 @@ frontend/*.ntvs*
frontend/*.njsproj
frontend/*.sln
frontend/*.sw?
2024-frontend/jsconfig.json

# Frontend cache
frontend/.eslintcache
Expand Down Expand Up @@ -180,4 +181,3 @@ notes/

# 2024 Frontend
.vite/
.hotfile
1 change: 1 addition & 0 deletions .hotfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://localhost:5173
12 changes: 12 additions & 0 deletions 2024-frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ma-cantine-server

WORKDIR /app/2024-frontend

USER root

# NB: this wont reinstall on build, must rebuild server image first
RUN npm install

EXPOSE 5173

CMD [ "npm", "run", "dev" ]
127 changes: 0 additions & 127 deletions 2024-frontend/jsconfig.json

This file was deleted.

3 changes: 3 additions & 0 deletions 2024-frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ export default defineConfig({
},
],
},
server: {
host: "0.0.0.0",
},
})
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

ARG PYTHON_VERSION=3.11
# slim is based on Debian
FROM python:${PYTHON_VERSION}-slim as base

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1

WORKDIR /app

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser

# in order to download the magic auth dependency, which comes from a github repo
# we need to install git
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git libpq-dev gcc npm

# i had a problem accessing github.com. When I followed https://docs.docker.com/desktop/get-started/#credentials-management-for-linux-users
# and restarted the problem was resolved

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
# Leverage a bind mount to requirements.txt to avoid having to copy them into
# into this layer.
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
python -m pip install -r requirements.txt

# Switch to the non-privileged user to run the application.
USER appuser

# Copy the source code into the container.
COPY . .

# Expose the port that the application listens on.
EXPOSE 8000

# Run the application.
CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]
Loading

0 comments on commit ed4a13d

Please sign in to comment.