Skip to content

Commit

Permalink
build(DOCKER): flexible and enforced user perms
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Feb 5, 2023
1 parent 4050714 commit 5f40433
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .github/scripts/build_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ set -eo pipefail

main() {

docker-compose build --build-arg PYTHON_VERSION="${PYTHON_VERSION}"
docker-compose build \
--build-arg BUILD_ARG_PYTHON_VERSION="${PYTHON_VERSION}" \
--build-arg BUILD_ARG_CONTAINER_GID="$(id -g)" \
--build-arg BUILD_ARG_CONTAINER_UID="$(id -u)"
docker-compose up -d

}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ jobs:
touch ${HOME}/.gitconfig
touch ${HOME}/.gitconfig_global
- name: Container Build -- Ensure File System is Writable by the Container
run: |
sudo chmod -R o+w .
- name: Container Build -- Build Container
run: |
source .github/scripts/build_container.sh
- name: Container Build -- Ensure GIT is working
run: |
docker-compose exec -T "${PROJECT_NAME}" git status
- name: Container Build -- Run TOML Linter
run: |
docker-compose exec -T "${PROJECT_NAME}" tomll /app/pyproject.toml
Expand Down
36 changes: 26 additions & 10 deletions assets/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ARG PYTHON_VERSION=3.8
FROM python:$PYTHON_VERSION-slim AS base
ARG BUILD_ARG_PYTHON_VERSION=3.8

FROM python:$BUILD_ARG_PYTHON_VERSION-slim AS base

ARG BUILD_ARG_CONTAINER_GID=1000
ARG BUILD_ARG_CONTAINER_UID=1000

LABEL maintainer="niall@niallbyrne.ca"
LABEL project="mac_maker"
Expand All @@ -24,17 +28,19 @@ RUN apt-get update && \
build-essential=12.* && \
rm -rf /var/lib/apt/lists/*

# Create the runtime user, and enforce permissions
RUN groupadd user -g "${BUILD_ARG_CONTAINER_GID}"
RUN useradd user -d /home/user \
-s /bin/bash \
-u "${BUILD_ARG_CONTAINER_UID}" \
-g "${BUILD_ARG_CONTAINER_GID}" \
-m

# Setup directories
RUN mkdir -p /home/user /app
RUN mkdir -p /app
RUN chown -R user:user /app
WORKDIR /app

# Create the runtime user, and enforce permissions
RUN useradd user -d /home/user \
-s /bin/bash \
-M && \
chown -R user:user /home/user && \
chown -R user:user /app

# Include the local binary folder in PATH
ENV PATH "/home/user/.local/bin/:${PATH}"

Expand Down Expand Up @@ -89,6 +95,11 @@ RUN poetry install --no-root -E docs
# Copy the Codebase
COPY . /app

# Enforce git repository permissions
USER root
RUN chown -R user:user /app
USER user

# Install the Application
RUN poetry install -E docs

Expand Down Expand Up @@ -143,4 +154,9 @@ RUN pip --no-cache-dir install -r requirements.txt
# Copy the codebase
COPY . /app

# Enforce git repository permissions
USER root
RUN chown -R user:user /app
USER user

CMD ["./mac_maker/container_init.sh"]

0 comments on commit 5f40433

Please sign in to comment.