-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dc7b89
commit 079f600
Showing
5 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
########### | ||
# BUILDER # | ||
########### | ||
|
||
# pull official base image | ||
FROM python:3.11.4-slim-buster as builder | ||
|
||
# set work directory | ||
WORKDIR /usr/src/app | ||
|
||
# set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# install system dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends gcc | ||
|
||
# lint | ||
RUN pip install --upgrade pip | ||
RUN pip install flake8==6.0.0 | ||
COPY . /usr/src/app/ | ||
RUN flake8 --ignore=E501,F401 . | ||
|
||
# install python dependencies | ||
COPY ./requirements.txt . | ||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt | ||
|
||
|
||
######### | ||
# FINAL # | ||
######### | ||
|
||
# pull official base image | ||
FROM python:3.11.4-slim-buster | ||
|
||
# create directory for the app user | ||
RUN mkdir -p /home/app | ||
|
||
# create the app user | ||
RUN addgroup --system app && adduser --system --group app | ||
|
||
# create the appropriate directories | ||
ENV HOME=/home/app | ||
ENV APP_HOME=/home/app/web | ||
RUN mkdir $APP_HOME | ||
WORKDIR $APP_HOME | ||
|
||
# install dependencies | ||
RUN apt-get update && apt-get install -y --no-install-recommends netcat | ||
COPY --from=builder /usr/src/app/wheels /wheels | ||
COPY --from=builder /usr/src/app/requirements.txt . | ||
RUN pip install --upgrade pip | ||
RUN pip install --no-cache /wheels/* | ||
|
||
# copy entrypoint.prod.sh | ||
COPY ./entrypoint.prod.sh . | ||
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.prod.sh | ||
RUN chmod +x $APP_HOME/entrypoint.prod.sh | ||
|
||
# copy project | ||
COPY . $APP_HOME | ||
|
||
# chown all the files to the app user | ||
RUN chown -R app:app $APP_HOME | ||
|
||
# change to the app user | ||
USER app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
version: "3.8" | ||
|
||
services: | ||
web: | ||
build: | ||
context: ./app | ||
dockerfile: Dockerfile.prod | ||
command: gunicorn perpus.wsgi:application --bind 0.0.0.0:8000 | ||
expose: | ||
- 8000 | ||
env_file: | ||
- ./.env.prod | ||
depends_on: | ||
- db | ||
|
||
db: | ||
image: mariadb | ||
container_name: perpus-db | ||
environment: | ||
MARIADB_DATABASE: "${MARIADB_DATABASE}" | ||
MARIADB_USER: "${MARIADB_USER}" | ||
MARIADB_PASSWORD: "${MARIADB_PASSWORD}" | ||
MARIADB_ROOT_PASSWORD: "${MARIADB_ROOT_PASSWORD}" | ||
MARIADB_TZ: "Asia/Makassar" | ||
command: "--default-time-zone=+08:00" | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- ./_tmpdb/mariadb:/var/lib/mysql | ||
networks: | ||
- perpus-app | ||
|
||
phpmyadmin: | ||
depends_on: | ||
- db | ||
image: phpmyadmin/phpmyadmin | ||
container_name: phpmyadmin | ||
restart: always | ||
ports: | ||
- 8080:80 | ||
links: | ||
- db:mysql | ||
environment: | ||
PMA_HOST: db | ||
MYSQL_USERNAME: root | ||
MYSQL_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD} | ||
PMA_ARBITRARY: 1 | ||
volumes: | ||
- /_tmpdb/phpmyadmin | ||
networks: | ||
- perpus-app | ||
|
||
nginx: | ||
build: ./nginx | ||
ports: | ||
- 1337:80 | ||
depends_on: | ||
- web | ||
|
||
networks: | ||
perpus-app: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM nginx:1.25 | ||
|
||
RUN rm /etc/nginx/conf.d/default.conf | ||
COPY nginx.conf /etc/nginx/conf.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
upstream perpus { | ||
server web:8000; | ||
} | ||
|
||
server { | ||
listen 80; | ||
|
||
location / { | ||
proxy_pass http://perpus; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $host; | ||
proxy_redirect off; | ||
} | ||
} |