Skip to content

Commit

Permalink
Added custom entrypoint with switch case, updated dockerfiles with ti…
Browse files Browse the repository at this point in the history
…ny package as entrypoint
  • Loading branch information
michalski-luc committed Dec 16, 2020
1 parent 66124bf commit f108d69
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ node_modules
node_modules/
node_modules/*
node_modules/**
shared/data
shared/data/
shared/data/*
shared/data/**
*.pid
4 changes: 4 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ REDIS_VERSION="6"
REDIS_USER=""
REDIS_PASSWD=""
REDIS_PORT="6379"
REDIS_MEMORY_MAX="1G"
REDIS_LOG_PREFIX_PATH="/var/logs/redis"
REDIS_LOG_FILENAME="monitor.log"
REDIS_LOG_FILE="${REDIS_LOG_PREFIX_PATH}/${REDIS_LOG_FILENAME}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
celerybeat-schedule
__pycache__
.DS_Store
*.pid

.env
node_modules
Expand Down
15 changes: 15 additions & 0 deletions admin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ COPY . .
EXPOSE 3000
VOLUME ["/app/build"]

LABEL name="seoz-admin" \
version="$VERSION" \
build="$BUILD" \
architecture="x86_64" \
build_date="$NOW" \
vendor="seoz" \
maintainer="Luc Michalski <[email protected]>" \
url="https://github.com/seoz.io/seoz-docker" \
summary="SeoZ project with Docker" \
description="SeoZ project with Docker" \
vcs-type="git" \
vcs-url="https://github.com/seoz.io/seoz-docker" \
vcs-ref="$VERSION" \
distribution-scope="public"

CMD ["yarn", "start"]
37 changes: 37 additions & 0 deletions admin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

set -x
set -e

isArgPassed() {
arg="$1"
argWithEqualSign="$1="
shift
while [ $# -gt 0 ]; do
passedArg="$1"
shift
case $passedArg in
$arg)
return 0
;;
$argWithEqualSign*)
return 0
;;
esac
done
return 1
}

case "$1" in

'bash')
ARGS=""
shift
apk add --update --no-cache nano bash jq
exec /bin/bash $@
;;

*)
exec yarn start $@
;;
esac
74 changes: 73 additions & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
FROM python:3-alpine
FROM python:3-alpine AS build
MAINTAINER Luc Michalski <[email protected]>

WORKDIR /opt/app

# Install Python and external dependencies, including headers and GCC
RUN apk add --no-cache libffi libffi-dev musl-dev gcc g++ git ca-certificates

# Update Pip3
RUN python3 -m pip install -U pi

# Install Pipenv
RUN pip3 install pipenv

# Create a virtual environment and activate it
RUN python3 -m venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH" \
VIRTUAL_ENV="/opt/venv"

COPY requirements.txt .

# Install dependencies into the virtual environment with Pipenv
RUN pip3 install -r requirements.txt

FROM python:3-alpine AS runtime
MAINTAINER Luc Michalski <[email protected]>

ARG VERSION
ARG BUILD
ARG NOW
ARG TINI_VERSION=${TINI_VERSION:-"v0.19.0"}

# Install tini to /usr/local/sbin
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-muslc-amd64 /usr/local/sbin/tini

# Install runtime dependencies & create runtime user
RUN apk --no-cache --no-progress add ca-certificates openssl libffi openblas libstdc++ \
&& chmod +x /usr/local/sbin/tini && mkdir -p /opt \
&& adduser -D seoz -h /opt/seoz -s /bin/sh \
&& su seoz -c 'cd /opt/seoz; mkdir -p bin config data'

# Switch to user context
USER seoz
WORKDIR /opt/seoz/data

# Copy the virtual environment from the previous image
COPY --from=build /opt/venv /opt/venv

# Activate the virtual environment
ENV PATH="/opt/venv/bin:$PATH" \
VIRTUAL_ENV="/opt/venv"

# Set container labels
LABEL name="seoz-server" \
version="$VERSION" \
build="$BUILD" \
architecture="x86_64" \
build_date="$NOW" \
vendor="seoz" \
maintainer="Luc Michalski <[email protected]>" \
url="https://github.com/seoz.io/seoz-docker" \
summary="SeoZ project with Docker" \
description="SeoZ project with Docker" \
vcs-type="git" \
vcs-url="https://github.com/seoz.io/seoz-docker" \
vcs-ref="$VERSION" \
distribution-scope="public"

# Container configuration
EXPOSE 5000
VOLUME ["/opt/seoz/data"]
ENTRYPOINT ["tini", "-g", "--"]
CMD ["./docker-entrypoint.sh"]
1 change: 0 additions & 1 deletion server/celerybeat.pid

This file was deleted.

42 changes: 42 additions & 0 deletions server/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

set -x
set -e

isArgPassed() {
arg="$1"
argWithEqualSign="$1="
shift
while [ $# -gt 0 ]; do
passedArg="$1"
shift
case $passedArg in
$arg)
return 0
;;
$argWithEqualSign*)
return 0
;;
esac
done
return 1
}

case "$1" in

# 'runserver')
# shift
# exec python3 manage.py runserver $@
# ;;

'bash')
ARGS=""
shift
apk add --update --no-cache nano bash jq
exec /bin/bash $@
;;

*)
exec python3 manage.py runserver $@
;;
esac

0 comments on commit f108d69

Please sign in to comment.