Skip to content

Commit

Permalink
Use multi stage Dockerfile build
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanaellio committed Nov 6, 2023
1 parent c5fd120 commit cb06989
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 54 deletions.
19 changes: 16 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Ignore files containing sensitive information
docker-compose.yaml
# Files containing sensitive information
melting_potlist.yaml
.env

# Ignore git metadata
# Git metadata
.git
.gitignore

# Docker files
Dockerfile
.dockerignore
docker-compose.yaml
docker-compose.example.yaml

# Python virtualenv
.venv

# Node modules
./vue_components/node_modules
38 changes: 18 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
FROM nikolaik/python-nodejs:python3.11-nodejs20
FROM node:lts as vite_build

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV NODE_ENV=production
ENV NODE_OPTIONS=--openssl-legacy-provider

# Fix Yarnpkg pub keys and install OS packages
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN apt-get update && apt-get -y install libpq-dev gcc build-essential

# Install and configure Poetry
RUN pip install "poetry==1.3.2"
RUN poetry config virtualenvs.create false

# Install NPM packages using PNPM
RUN npm install -g pnpm
WORKDIR /usr/src/app/vue_components
# RUN mkdir --parents /usr/src/app/vue_components
WORKDIR /build/vue_components
COPY ["./vue_components/package.json", "./vue_components/pnpm-lock.yaml", "./"]
RUN pnpm install --prod

# Build using vite
COPY ./vue_components ./
RUN pnpm run build


FROM python:3.12 as django_app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Install and configure Poetry
RUN pip install "poetry==1.7.0"
RUN poetry config virtualenvs.create false

# Install Python packages
WORKDIR /usr/src/app
COPY ./pyproject.toml ./poetry.lock ./
RUN poetry install --only main --no-root --no-interaction --no-ansi

COPY . /usr/src/app/

# Build vue webpack bundle
WORKDIR /usr/src/app/vue_components
RUN pnpm run build

WORKDIR /usr/src/app
COPY . ./
COPY --from=vite_build /build/vue_components/dist /usr/src/app/vue_components/dist
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
10 changes: 10 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vue_components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"pnpm": "^8.10.2",
"vite": "^4.5.0",
"vue": "^3.3.7",
"vue-multiselect": "3.0.0-beta.3",
"webpack-bundle-tracker": "^1.4.0"
"vue-multiselect": "3.0.0-beta.3"
},
"devDependencies": {
"prettier": "1.19.1"
Expand Down
29 changes: 0 additions & 29 deletions vue_components/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb06989

Please sign in to comment.