-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy using
Dockerfile
instead of buildpack
Somewhat based on the Dockfile template in Rails: https://github.com/rails/rails/blob/4f0f3448cde85ff3d1485366231650258ea62b71/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt Needed after heroku/heroku-buildpack-ruby#1428 because deploys failed like this: ... Machine started in 390ms Activating bundler (>= 0.a) failed: Permission denied @ rb_sysopen - /workspace/vendor/bundle/ruby/3.2.0/specifications/bundler-2.5.6.gemspec To install the version of bundler this project requires, run `gem install bundler -v '>= 0.a'`
- Loading branch information
Showing
20 changed files
with
185 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
ARG RUBY_VERSION | ||
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base | ||
|
||
# The app lives here | ||
WORKDIR /app | ||
|
||
# Install base packages | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y \ | ||
curl \ | ||
postgresql-client | ||
|
||
# Set production environment | ||
ENV BUNDLE_DEPLOYMENT="1" \ | ||
BUNDLE_PATH="/usr/local/bundle" \ | ||
BUNDLE_CACHE_PATH="/usr/local/bundle/cache" \ | ||
BUNDLE_WITHOUT="development" | ||
|
||
# Throw-away build stage to reduce size of final image | ||
FROM base as build | ||
|
||
# Install build packages | ||
RUN apt-get install --no-install-recommends -y \ | ||
build-essential \ | ||
git \ | ||
libpq-dev \ | ||
pkg-config | ||
|
||
# Install application gems | ||
COPY Gemfile Gemfile.lock .ruby-version ./ | ||
COPY vendor/cache "${BUNDLE_CACHE_PATH}" | ||
RUN bundle install --local | ||
|
||
# Copy application code | ||
COPY . . | ||
|
||
# Final stage for app image | ||
FROM base | ||
|
||
ARG APPUSER=app | ||
ARG APPDIR=/app | ||
|
||
# Clean up installation packages to reduce image size | ||
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
|
||
# Copy built artifacts: gems, application | ||
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" | ||
COPY --from=build $APPDIR $APPDIR | ||
|
||
# Run and own only the runtime files as a non-root user for security | ||
RUN mkdir -p log tmp | ||
RUN groupadd --system --gid 1000 $APPUSER | ||
RUN useradd $APPUSER --uid 1000 --gid 1000 --create-home --shell /bin/bash | ||
RUN chown -R $APPUSER:$APPUSER log tmp | ||
USER 1000:1000 | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
CMD bin/start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: bundle exec puma -C config/puma.rb | ||
web: bundle exec puma --config config/puma.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
TAG=${TAG:-wikimum} | ||
|
||
set -e | ||
set -x | ||
|
||
docker build . --build-arg RUBY_VERSION=$(cat .ruby-version) --tag $TAG "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -x | ||
|
||
RUBY_VERSION=$(cat .ruby-version) docker compose up \ | ||
--build \ | ||
--always-recreate-deps \ | ||
--force-recreate \ | ||
--remove-orphans \ | ||
--renew-anon-volumes \ | ||
"$@" | ||
|
||
# this script is useful if you run into some strange problem with the docker setup | ||
|
||
# --always-recreate-deps Recreate dependent containers. Incompatible with --no-recreate. | ||
# --force-recreate Recreate containers even if their configuration and image haven't changed. | ||
# --remove-orphans Remove containers for services not defined in the Compose file. | ||
#-V, --renew-anon-volumes Recreate anonymous volumes instead of retrieving data from the previous containers. | ||
|
||
# these flags will make use of more disk space | ||
# check and clean up with | ||
# | ||
# docker system df | ||
# docker system prune |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -x | ||
|
||
RUBY_VERSION=$(cat .ruby-version) docker compose up \ | ||
--build \ | ||
"$@" | ||
|
||
# useful but mutually exclusive flags | ||
# --detach | ||
# --exit-code-from app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
RUBY_VERSION=$(cat .ruby-version) docker compose up \ | ||
--build \ | ||
--detach \ | ||
--wait | ||
|
||
curl \ | ||
--verbose \ | ||
--silent \ | ||
--output /dev/null \ | ||
--fail-with-body \ | ||
--retry 5 \ | ||
--retry-all-errors \ | ||
--retry-connrefused \ | ||
127.0.0.1:8080 | ||
|
||
result=$? | ||
|
||
docker compose stop | ||
|
||
exit $result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ set -e | |
set -u | ||
|
||
bundle exec rake db:migrate | ||
bundle exec puma --config config/puma.rb |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SESSION_SECRET=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: "3.9" | ||
services: | ||
app: | ||
build: | ||
context: . | ||
args: | ||
- RUBY_VERSION | ||
ports: | ||
- "127.0.0.1:8080:3000" | ||
env_file: | ||
- ./default.env | ||
environment: | ||
DATABASE_URL: postgres://postgres:postgres@db/db | ||
PORT: 3000 | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
db: | ||
image: postgres | ||
restart: always | ||
# set shared memory limit when using docker-compose | ||
# https://github.com/docker-library/postgres/issues/416 | ||
shm_size: 128mb | ||
environment: | ||
POSTGRES_DB: db | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready --dbname=db --username=postgres"] | ||
interval: 2s | ||
retries: 10 | ||
start_period: 20s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.