Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle file permissions in a cleaner way while building Docker images #3238

Merged
merged 2 commits into from Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions bin/docker_wrapper

This file was deleted.

2 changes: 1 addition & 1 deletion build_docker_image.sh
Expand Up @@ -5,7 +5,7 @@ set -e
: ${DOCKER_IMAGE_TAG:=${GITHUB_SHA:-$(git rev-parse HEAD)}}
: ${DOCKERFILE:=docker/multi-process/Dockerfile}

bin/docker_wrapper build $BUILD_ARGS -t "$DOCKER_IMAGE" -f "$DOCKERFILE" .
docker build $BUILD_ARGS -t "$DOCKER_IMAGE" -f "$DOCKERFILE" .

if [[ "$1" == --push ]]; then
[[ -n "$DOCKER_USER" && -n "$DOCKER_IMAGE_TAG" ]]
Expand Down
28 changes: 15 additions & 13 deletions docker/multi-process/Dockerfile
Expand Up @@ -12,29 +12,33 @@ ENV HOME=/app

ARG UID=1001
RUN useradd -u "$UID" -g 0 -d /app -s /sbin/nologin -c "default user" default
RUN chown -R "$UID:0" /app
USER $UID

ENV LC_ALL=en_US.UTF-8
ENV RAILS_ENV=production

COPY ["Gemfile", "Gemfile.lock", "/app/"]
COPY lib/gemfile_helper.rb /app/lib/
COPY vendor/gems/ /app/vendor/gems/
COPY --chown="$UID:0" ["Gemfile", "Gemfile.lock", "/app/"]
COPY --chown="$UID:0" lib/gemfile_helper.rb /app/lib/
RUN mkdir /app/vendor
COPY --chown="$UID:0" vendor/gems/ /app/vendor/gems/

ARG ADDITIONAL_GEMS=
ENV ADDITIONAL_GEMS=$ADDITIONAL_GEMS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea, this allows one to bake agent gems into their docker image to avoid the additional bundle install time at startup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, actually I didn't notice that the startup process ran bundle install, and building my own Docker image has been how I build and use Huginn, and thought this should be everybody's option. 😊


# Get rid of annoying "fatal: Not a git repository (or any of the parent directories): .git" messages
RUN umask 002 && git init && \
RUN git init && \
bundle config set --local path vendor/bundle && \
bundle config set --local without 'test development' && \
APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle install -j 4
bundle config set --local without 'test development'

RUN APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle install -j 4

COPY ./ /app/
COPY --chown="$UID:0" ./ /app/

ARG OUTDATED_DOCKER_REGISTRY=false
ENV OUTDATED_DOCKER_REGISTRY=${OUTDATED_DOCKER_REGISTRY}

RUN umask 002 && \
APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle exec rake assets:clean assets:precompile && \
chmod g=u /app/.env.example /app/Gemfile.lock /app/config/ /app/tmp/ && \
chown -R "$UID" /app
RUN APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle exec rake assets:clean assets:precompile

EXPOSE 3000

Expand All @@ -48,6 +52,4 @@ COPY ["docker/multi-process/scripts/bootstrap.sh", \
"docker/scripts/setup_env", "/scripts/"]
CMD ["/scripts/init"]

USER $UID

VOLUME /var/lib/mysql
2 changes: 1 addition & 1 deletion docker/multi-process/README.md
Expand Up @@ -116,7 +116,7 @@ In newer versions of Docker you are able to pass your own .env file in to the co

You don't need to do this on your own, because there is an [automated build](https://hub.docker.com/r/huginn/huginn/) for this repository, but if you really want run this command in the Huginn root directory:

bin/docker_wrapper build --rm=true --tag={yourname}/huginn -f docker/multi-process/Dockerfile .
docker build --rm=true --tag={yourname}/huginn -f docker/multi-process/Dockerfile .

## Source

Expand Down
28 changes: 15 additions & 13 deletions docker/single-process/Dockerfile
Expand Up @@ -9,33 +9,35 @@ ENV HOME=/app

ARG UID=1001
RUN useradd -u "$UID" -g 0 -d /app -s /sbin/nologin -c "default user" default
RUN chown -R "$UID:0" /app
USER $UID

ENV LC_ALL=en_US.UTF-8
ENV RAILS_ENV=production

COPY ["Gemfile", "Gemfile.lock", "/app/"]
COPY lib/gemfile_helper.rb /app/lib/
COPY vendor/gems/ /app/vendor/gems/
COPY --chown="$UID:0" ["Gemfile", "Gemfile.lock", "/app/"]
COPY --chown="$UID:0" lib/gemfile_helper.rb /app/lib/
RUN mkdir /app/vendor
COPY --chown="$UID:0" vendor/gems/ /app/vendor/gems/

ARG ADDITIONAL_GEMS=
ENV ADDITIONAL_GEMS=$ADDITIONAL_GEMS

# Get rid of annoying "fatal: Not a git repository (or any of the parent directories): .git" messages
RUN umask 002 && git init && \
RUN git init && \
bundle config set --local path vendor/bundle && \
bundle config set --local without 'test development' && \
APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle install -j 4
bundle config set --local without 'test development'

RUN APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle install -j 4

COPY ./ /app/
COPY --chown="$UID:0" ./ /app/

ARG OUTDATED_DOCKER_REGISTRY=false
ENV OUTDATED_DOCKER_REGISTRY=${OUTDATED_DOCKER_REGISTRY}

RUN umask 002 && \
APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle exec rake assets:clean assets:precompile && \
chmod g=u /app/.env.example /app/Gemfile.lock /app/config/ /app/tmp/ && \
chown -R "$UID" /app
RUN APP_SECRET_TOKEN=secret DATABASE_ADAPTER=mysql2 ON_HEROKU=true bundle exec rake assets:clean assets:precompile

EXPOSE 3000

COPY ["docker/scripts/setup_env", "docker/single-process/scripts/init", "/scripts/"]
CMD ["/scripts/init"]

USER $UID
2 changes: 1 addition & 1 deletion docker/single-process/README.md
Expand Up @@ -98,7 +98,7 @@ In newer versions of Docker you are able to pass your own .env file in to the co

You don't need to do this on your own, but if you really want run this command in the Huginn root directory:

bin/docker_wrapper build --rm=true --tag={yourname}/huginn -f docker/single-process/Dockerfile .
docker build --rm=true --tag={yourname}/huginn -f docker/single-process/Dockerfile .

## Source

Expand Down