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

Fix Broken Container and Other Dockerfile Improvements #2981

Merged
merged 7 commits into from
Feb 2, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/docker-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ on:
# * is a special character in YAML so you have to quote this string
# Run every day at 5:24 UTC - build 'nightly' docker containers
- cron: "24 17 * * *"

pull_request_target:
types:
- labeled

env:
DOCKER_PUSH: true
jobs:
pwpush-container:
if: github.event.label && github.event.label.name == 'docker' || github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -38,6 +44,7 @@ jobs:
with:
images: ${{ secrets.DOCKER_USERNAME }}/pwpush
tags: |
type=ref,event=pr,format=pr-{{ref}}-docker
type=match,pattern=stable
type=schedule,pattern=nightly
type=semver,pattern={{version}}
Expand All @@ -64,6 +71,7 @@ jobs:
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush:buildcache,mode=max,ignore-error=${{env.DOCKER_PUSH == 'false'}}

public-gateway-container:
if: github.event.label && github.event.label.name == 'docker' || github.event_name != 'pull_request_target'
needs: pwpush-container
runs-on: ubuntu-latest
steps:
Expand All @@ -82,6 +90,7 @@ jobs:
with:
images: ${{ secrets.DOCKER_USERNAME }}/pwpush-public-gateway
tags: |
type=ref,event=pr,format=pr-{{ref}}-docker
type=match,pattern=stable
type=schedule,pattern=nightly
type=semver,pattern={{version}}
Expand All @@ -108,6 +117,7 @@ jobs:
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush-public-gateway:buildcache,mode=max,ignore-error=${{env.DOCKER_PUSH == 'false'}}

worker-container:
if: github.event.label && github.event.label.name == 'docker' || github.event_name != 'pull_request_target'
needs: pwpush-container
runs-on: ubuntu-latest
steps:
Expand All @@ -126,6 +136,7 @@ jobs:
with:
images: ${{ secrets.DOCKER_USERNAME }}/pwpush-worker
tags: |
type=ref,event=pr,format=pr-{{ref}}-docker
type=match,pattern=stable
type=schedule,pattern=nightly
type=semver,pattern={{version}}
Expand Down
31 changes: 16 additions & 15 deletions containers/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ ENV RACK_ENV=production RAILS_ENV=production

RUN bundle config set without "${BUNDLE_WITHOUT}" \
&& bundle config set deployment "${BUNDLE_DEPLOYMENT}" \
&& bundle install

# Removing unneccesary files/directories
RUN rm -rf vendor/bundle/ruby/*/cache \
&& bundle install --jobs=4 --retry=3 \
&& rm -rf vendor/bundle/ruby/*/cache \
&& rm -rf vendor/bundle/ruby/*/bundler/gems/*/.git \
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete
Expand All @@ -60,15 +58,14 @@ ENV DATABASE_URL=sqlite3:db/db.sqlite3
# SECRET_KEY_BASE=<value>
ENV SECRET_KEY_BASE=783ff1544b9612d8bceb8e26a0bab0cf22543eec658a498e7ef9e1d617976f960092005c8a54cb588759dc6dd8fd054bc4eca4a94dd7b96c6efda4a14a01bfbd

# Precompile bootsnap cache for gems to improve load time
# This creates a cache of the gem requires which speeds up application boot
# Precompile bootsnap cache for gems an application code to improve load time
# This creates a cache of the gem requires and application code which speeds up application boot
# Note: This must be run AFTER bundle install since it caches the installed gems
RUN bundle exec bootsnap precompile --gemfile
# Precompile bootsnap cache for application code to improve load time
# This creates a cache of the application code which speeds up application boot
RUN bundle exec bootsnap precompile app/ lib/
RUN bundle exec rails assets:precompile
RUN bundle exec rake db:setup
RUN bundle exec bootsnap precompile --gemfile \
&& bundle exec bootsnap precompile app/ lib/ \
&& bundle exec rails assets:precompile \
&& bundle exec rake db:setup \
&& rm -rf tmp/cache tmp/pids tmp/sockets

################## Build done ##################

Expand All @@ -95,14 +92,15 @@ RUN apk add --no-cache \
ARG UID=1000
ARG GID=1000

RUN addgroup -g "${GID}" pwpusher \
&& adduser -D -u "${UID}" -G pwpusher pwpusher

ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
ENV APP_ROOT=/opt/PasswordPusher
WORKDIR ${APP_ROOT}
ENV RACK_ENV=production RAILS_ENV=production

RUN addgroup -g "${GID}" pwpusher \
&& adduser -D -u "${UID}" -G pwpusher pwpusher \
&& chown -R pwpusher:pwpusher ${APP_ROOT}

# Set a default secret_key_base
# For those self-hosting this app, you should
# generate your own secret_key_base and set it
Expand All @@ -115,6 +113,9 @@ ENV SECRET_KEY_BASE=783ff1544b9612d8bceb8e26a0bab0cf22543eec658a498e7ef9e1d61797

COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}

RUN bundle config set without "${BUNDLE_WITHOUT}" \
&& bundle config set deployment "${BUNDLE_DEPLOYMENT}"

USER pwpusher
EXPOSE 5100
ENTRYPOINT ["containers/docker/entrypoint.sh"]
Loading