Skip to content

Commit

Permalink
add git rev and build date to docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 26, 2023
1 parent 6d7295f commit ac51fbd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.venv
.vscode
.github
.git
.gitignore
.pre-commit-config.yaml
__pycache__
Expand Down
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ ENV PYTHONUNBUFFERED=1
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt apt-get update \
&& apt-get install -y --no-install-recommends build-essential libpq-dev python3-venv git

COPY requirements.txt /neodb/
COPY . /neodb

RUN echo neodb-`cd /neodb && git rev-parse --short HEAD`-`cd /neodb/neodb-takahe && git rev-parse --short HEAD`-`date -u +%Y%m%d%H%M%S` > /neodb/version
RUN rm -rf /neodb/.git /neodb/neodb-takahe/.git

RUN mv /neodb/neodb-takahe /takahe

WORKDIR /neodb
RUN python -m venv /neodb-venv
RUN --mount=type=cache,sharing=locked,target=/root/.cache /neodb-venv/bin/python3 -m pip install --upgrade -r requirements.txt

COPY neodb-takahe/requirements.txt /takahe/
WORKDIR /takahe
RUN python -m venv /takahe-venv
RUN --mount=type=cache,sharing=locked,target=/root/.cache /takahe-venv/bin/python3 -m pip install --upgrade -r requirements.txt

RUN apt-get purge -y --auto-remove build-essential && rm -rf /var/lib/apt/lists/*

# runtime stage
FROM python:3.11-slim as runtime
ENV PYTHONDONTWRITEBYTECODE=1
Expand All @@ -32,23 +35,23 @@ RUN busybox --install

# postgresql and redis cli are not required, but install for development convenience
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt-run apt-get install -y --no-install-recommends postgresql-client redis-tools
RUN useradd -U app
RUN rm -rf /var/lib/apt/lists/*

COPY . /neodb
COPY --from=build /neodb /neodb
WORKDIR /neodb
COPY --from=build /neodb-venv /neodb-venv
RUN /neodb-venv/bin/python3 manage.py compilescss
RUN /neodb-venv/bin/python3 manage.py collectstatic --noinput

RUN mv /neodb/neodb-takahe /takahe
COPY --from=build /takahe /takahe
WORKDIR /takahe
COPY --from=build /takahe-venv /takahe-venv
RUN TAKAHE_DATABASE_SERVER="postgres://x@y/z" TAKAHE_SECRET_KEY="t" TAKAHE_MAIN_DOMAIN="x.y" /takahe-venv/bin/python3 manage.py collectstatic --noinput

WORKDIR /neodb
COPY misc/bin/* /bin/
RUN mkdir -p /www
RUN useradd -U app
RUN rm -rf /var/lib/apt/lists/*

USER app:app

Expand Down
1 change: 1 addition & 0 deletions misc/bin/neodb-hello
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
echo '\033[0;35m====== Welcome to NeoDB ======\033[0m'
cat /neodb/version
echo Your configuration is for ${NEODB_SITE_NAME} on ${NEODB_SITE_DOMAIN}
[[ -z "${NEODB_DEBUG}" ]] || echo DEBUG is ON
[[ -z "${NEODB_DEBUG}" ]] || env
Expand Down
1 change: 1 addition & 0 deletions misc/bin/neodb-init
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
echo '\033[0;35m====== Welcome to NeoDB ======\033[0m'
cat /neodb/version
echo Your configuration is for ${NEODB_SITE_NAME} on ${NEODB_SITE_DOMAIN}
[[ -z "${NEODB_DEBUG}" ]] || echo DEBUG is ON, show environment:
[[ -z "${NEODB_DEBUG}" ]] || env
Expand Down

0 comments on commit ac51fbd

Please sign in to comment.