Skip to content

Commit

Permalink
testing new docker strat
Browse files Browse the repository at this point in the history
  • Loading branch information
seplee committed Apr 6, 2024
1 parent adff93d commit 99f22ce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion _infrastructure/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd web || exit 1
# Build and run Dockerfile
cd api || exit 1

docker build . -f cloud/Dockerfile -t drive-gooder-container-repository:"${CONTAINER_TAG}".
docker build . -f cloud/Final.Dockerfile -t drive-gooder-container-repository:"${CONTAINER_TAG}".

docker run -d \
-p 80:80 \
Expand Down
27 changes: 26 additions & 1 deletion api/cloud/BaseImage.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,33 @@ RUN apt-get -y install nginx \
ENV PYTHONUNBUFFERED=1
# Don't create `.pyc` files:
ENV PYTHONDONTWRITEBYTECODE=1

WORKDIR "/app"

RUN groupadd --gid 1010 socketWriters \
&& usermod -a -G socketWriters www-data \
&& pwd=$(cat /proc/sys/kernel/random/uuid) \
&& echo "$pwd" > password \
# create appUser
# gid 1010 is socketWriters
# uid 1007 will own the /app dir
# Coqui saves models to the user's home dir, so we need to create a user with a home dir
&& useradd -u 1007 -g 1010 -m -p "$(cat password)" appUser \
&& shred -u password \
# set HOME on non-login user changes for appUser:
&& sed -i '1s;^;export HOME="/home/appUser"\n;' /home/appUser/.bashrc \
&& sed -i '1s;^;echo "running bashrc for appUser"\n;' /home/appUser/.bashrc \
&& sed -i '1s;^;source ./.venv/bin/activate\n;' /home/appUser/.bashrc &&\
# Create the .local and share directories if useradd does not make them
if [ ! -d "/home/appUser/.local" ]; then \
mkdir -p "/home/appUser/.local/share/tts" \
# coqui seems to use both tts and tts-caches
mkdir -p "/home/appUser/.local/share/tts-cache" \
chown -R appUser "/home/appUser/" \
fi \
# make appUser owner of /app. This operation takes a long time
&& chown -R appUser /app

USER appUser
RUN pip install --upgrade pip
RUN pip install poetry && poetry config virtualenvs.in-project true
COPY poetry.lock pyproject.toml ./
Expand Down
29 changes: 15 additions & 14 deletions api/cloud/Final.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ FROM halzinnia/drive-gooder-base:v0.0.3
ARG WORKDIR
WORKDIR ${WORKDIR}

COPY backend backend
COPY cloud/start.sh cloud/uwsgi.ini ./
RUN chmod +x start.sh
COPY ./cloud/nginx.conf /etc/nginx

# copy built static FE to docker image
COPY /build frontend

# create ssl cert to encrypt requests between FE and BE
# too careful? maybe
RUN cd /etc/nginx/certs \
# too careful? maybe.
RUN mkdir /etc/nginx/certs \
&& cd /etc/nginx/certs \
&& openssl req -x509 -newkey \
rsa:4096 -keyout key.pem -out cert.pem \
-sha256 -days 365 -nodes -subj "/C=US/ST=IN/L=Indianapolis/O=BTYT/OU=clowns/CN=drive-gooder"

# configure appUser
COPY cloud/appUser.sh cloud/appUserStart.sh ./
RUN chmod +x appUser.sh appUserStart.sh
RUN ./appUser.sh
COPY ./cloud/nginx.conf /etc/nginx

# We're trying this int he BaseImage now:
# setup appUser, uid 1007 and gid 1010 (socketwriters group)
# COPY cloud/appUser.sh ./
# RUN chmod +x appUser.sh \
# && ./appUser.sh

COPY --chown=1007:1010 backend backend
COPY --chown=1007:1010 /build frontend
COPY --chown=1007:1010 cloud/start.sh cloud/uwsgi.ini cloud/appUserStart.sh ./
RUN chmod +x start.sh appUserStart.sh

# add a dev ssh key
# RUN mkdir /home/appUser/.ssh
Expand Down
3 changes: 2 additions & 1 deletion api/cloud/appUser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ echo "$pwd" > password

# create appUser
# gid 1010 is socketWriters
useradd -g 1010 -m -p "$(cat password)" appUser # create user with a home dir. Coqui saves models to the user's home dir
# uid 1007 will own the /app dir
useradd -u 1007 -g 1010 -m -p "$(cat password)" appUser # create user with a home dir. Coqui saves models to the user's home dir
shred -u password

# set HOME on non-login user changes for appUser:
Expand Down

0 comments on commit 99f22ce

Please sign in to comment.