import files
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
FROM hashicorp/terraform:light as dist
|
||||
ARG DOCKER_BUILD_DIR
|
||||
|
||||
RUN apk --no-cache upgrade
|
||||
|
||||
FROM dist as local
|
||||
ARG DOCKER_BUILD_DIR
|
||||
ARG UID
|
||||
ARG USER
|
||||
ENV UID=${UID}
|
||||
ENV GID=${UID}
|
||||
ENV USER=${USER}
|
||||
LABEL com.1001pharmacies.uid=${UID}
|
||||
LABEL com.1001pharmacies.user=${USER}
|
||||
|
||||
# If we provide a numeric UID
|
||||
RUN [ "$UID" -eq "$UID" ] 2>/dev/null \
|
||||
# Remove user with $UID if it is not our $USER
|
||||
&& if [ "$(getent passwd $UID |awk -F: '{print $1}')" != "$USER" ]; then \
|
||||
sed -i '/^'$(getent passwd $UID |awk -F: '{print $1}')':x:'$UID':/d' /etc/passwd; \
|
||||
sed -i '/^'$(getent group $GID |awk -F: '{print $1}')':x:'$GID':/d' /etc/group; \
|
||||
fi \
|
||||
# Force $UID if our $USER already exists
|
||||
&& sed -i 's/^'$USER':x:[0-9]\+:[0-9]\+:/'$USER':x:'$UID':'$GID':/' /etc/passwd \
|
||||
&& sed -i 's/^'$USER':x:[0-9]\+:/'$USER':x:'$GID':/' /etc/group \
|
||||
# Create $USER if it does not exist
|
||||
&& if [ "$(getent passwd $UID)" = "" ]; then \
|
||||
echo "$USER:x:$UID:$GID::/home/$USER:$SHELL" >> /etc/passwd; \
|
||||
echo "$USER:\!:$(($(date +%s) / 60 / 60 / 24)):0:99999:7:::" >> /etc/shadow; \
|
||||
echo "$USER:x:$GID:" >> /etc/group; \
|
||||
fi \
|
||||
&& mkdir -p /home/$USER \
|
||||
&& chown $UID:$GID /home/$USER \
|
||||
|| true
|
||||
|
||||
USER $USER
|
||||
|
||||
FROM local as debug
|
||||
ARG DOCKER_BUILD_DIR
|
||||
|
||||
FROM local as tests
|
||||
ARG DOCKER_BUILD_DIR
|
||||
|
||||
FROM tests as preprod
|
||||
ARG DOCKER_BUILD_DIR
|
||||
|
||||
FROM preprod as prod
|
||||
ARG DOCKER_BUILD_DIR
|
||||
Reference in New Issue
Block a user