mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-23 09:29:43 -04:00
Add gosu and host user to Docker
This commit is contained in:
@@ -5,7 +5,8 @@ ARG HTTPS_PROXY
|
||||
ARG NO_PROXY
|
||||
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
DEBIAN_FRONTEND=noninteractive
|
||||
DEBIAN_FRONTEND=noninteractive \
|
||||
GOSU_VERSION=1.10
|
||||
|
||||
RUN \
|
||||
echo "Install base packages" \
|
||||
@@ -19,14 +20,6 @@ RUN \
|
||||
zip \
|
||||
libpq-dev \
|
||||
jq \
|
||||
|
||||
&& echo "Install Cloud Foundry CLI" \
|
||||
&& curl -sSL "https://cli.run.pivotal.io/stable?release=debian64&source=github" -o /tmp/cloudfoundry-cli.deb \
|
||||
&& dpkg -i /tmp/cloudfoundry-cli.deb \
|
||||
&& cf install-plugin -r CF-Community -f "autopilot" \
|
||||
&& cf install-plugin -r CF-Community -f "blue-green-deploy" \
|
||||
&& cf install-plugin -r CF-Community -f "antifreeze" \
|
||||
|
||||
&& echo "Clean up" \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/*
|
||||
|
||||
@@ -37,4 +30,29 @@ RUN \
|
||||
awscli \
|
||||
wheel
|
||||
|
||||
RUN \
|
||||
echo "Install Cloud Foundry CLI" \
|
||||
&& curl -sSL "https://cli.run.pivotal.io/stable?release=debian64&source=github" -o /tmp/cloudfoundry-cli.deb \
|
||||
&& dpkg -i /tmp/cloudfoundry-cli.deb \
|
||||
&& cf install-plugin -r CF-Community -f "autopilot" \
|
||||
&& cf install-plugin -r CF-Community -f "blue-green-deploy" \
|
||||
&& cf install-plugin -r CF-Community -f "antifreeze"
|
||||
|
||||
COPY tianon.gpg /tmp/tianon.gpg
|
||||
|
||||
RUN \
|
||||
echo "Install gosu" \
|
||||
&& curl -sSL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
||||
&& curl -sSL -o /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --import /tmp/tianon.gpg \
|
||||
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
||||
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
&& gosu nobody true
|
||||
|
||||
WORKDIR /var/project
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
|
||||
|
||||
@@ -19,5 +19,15 @@ build:
|
||||
.PHONY: bash
|
||||
bash:
|
||||
docker run -it --rm \
|
||||
govuk/notify-api-builder \
|
||||
-e UID=$(shell id -u) \
|
||||
-e GID=$(shell id -g) \
|
||||
govuk/notify-api-builder:${DOCKER_IMAGE_TAG} \
|
||||
bash
|
||||
|
||||
.PHONY: bash
|
||||
bash-hostuser:
|
||||
docker run -it --rm \
|
||||
-e UID=$(shell id -u) \
|
||||
-e GID=$(shell id -g) \
|
||||
govuk/notify-api-builder:${DOCKER_IMAGE_TAG} \
|
||||
gosu hostuser bash
|
||||
|
||||
33
docker/entrypoint.sh
Executable file
33
docker/entrypoint.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ "$TRACE" ]] && set -x
|
||||
|
||||
if [[ "$(id -u)" -ne 0 ]]; then
|
||||
echo 'docker-entrypoint requires root' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$UID" ] || [ "$UID" = "0" ]; then
|
||||
echo "UID must be specified as a positive integer"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$GID" ] || [ "$GID" = "0" ]; then
|
||||
echo "GID must be specified as positive integer"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
USER=$(id -un $UID 2>/dev/null || echo "hostuser")
|
||||
GROUP=$(getent group $GID | cut -d: -f1 || echo "hostgroup")
|
||||
|
||||
if [ "$USER" = "hostuser" ]; then
|
||||
useradd -u $UID -s /bin/bash -m $USER
|
||||
fi
|
||||
|
||||
if [ "$GROUP" = "hostgroup" ]; then
|
||||
groupadd -g $GID $GROUP
|
||||
fi
|
||||
|
||||
usermod -g $GROUP $USER
|
||||
|
||||
exec "$@"
|
||||
BIN
docker/tianon.gpg
Normal file
BIN
docker/tianon.gpg
Normal file
Binary file not shown.
Reference in New Issue
Block a user