Created
April 16, 2024 20:47
-
-
Save kostyay/482da93c4a68d582abbb6bb9ed1779e1 to your computer and use it in GitHub Desktop.
Rails app with Postgres and Caddy on Hetzner VPS with Docker Compose
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
{ | |
email [email protected] | |
} | |
my.host.com { | |
encode zstd gzip | |
log { | |
output stdout | |
} | |
reverse_proxy * { | |
to rails-app:3000 | |
transport http { | |
read_buffer 8192 | |
} | |
header_up Access-Control-Allow-Origin * | |
header_up Access-Control-Allow-Credentials true | |
header_up Access-Control-Allow-Headers Cache-Control,Content-Type | |
} | |
header /assets/*.js { | |
Content-Type "text/javascript; charset=utf-8" | |
} | |
header /assets/*.css { | |
Content-Type "text/css; charset=utf-8" | |
} | |
} |
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
version: "3.9" | |
services: | |
caddy: | |
image: caddy:2.4.3-alpine | |
restart: unless-stopped | |
ports: | |
- 443:443 | |
- 80:80 | |
volumes: | |
- ${PWD}/caddy:/data | |
- ${PWD}/Caddyfile:/etc/caddy/Caddyfile | |
db: | |
image: postgres:14.9 | |
restart: always | |
environment: | |
POSTGRES_PASSWORD: "zzz" | |
POSTGRES_USER: "uuu" | |
POSTGRES_DB: "mydb" | |
volumes: | |
- ./postgres-data:/var/lib/postgresql/data | |
healthcheck: | |
test: ["CMD-SHELL", "pg_isready -U mydb"] | |
interval: 5s | |
timeout: 5s | |
retries: 5 | |
rails-app: | |
image: my-image:latest | |
privileged: true | |
environment: | |
RAILS_ENV: "production" | |
DATABASE_URL: "postgres://uuu:zz@db/mydb?pool=5" | |
SECRET_KEY_BASE: AAA | |
RAILS_SERVE_STATIC_FILES: "true" | |
depends_on: | |
db: | |
condition: service_healthy |
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
FROM ruby:3.1.4-slim | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
build-essential \ | |
libpq-dev \ | |
postgresql-client \ | |
git \ | |
nodejs npm \ | |
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
RUN npm install -g yarn | |
RUN gem update --system | |
# use a global path instead of vendor | |
ENV GEM_HOME="/usr/local/bundle" | |
ENV BUNDLE_PATH="$GEM_HOME" | |
ENV BUNDLE_SILENCE_ROOT_WARNING=1 | |
ENV BUNDLE_APP_CONFIG="$GEM_HOME" | |
ENV PATH="$GEM_HOME/bin:$BUNDLE_PATH/gems/bin:${PATH}" | |
# make 'docker logs' work | |
ENV RAILS_LOG_TO_STDOUT=true | |
ENV RAILS_ENV=production | |
ENV RAILS_SERVE_STATIC_FILES=true | |
WORKDIR /usr/src/app | |
COPY Gemfile Gemfile | |
COPY Gemfile.lock Gemfile.lock | |
RUN bundle install --jobs 4 --without development test | |
COPY . . | |
RUN rm -f tmp/pids/server.pid | |
EXPOSE 3000 | |
CMD ["./entrypoint.sh"] |
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
#! /bin/bash | |
rm -f tmp/pids/server.pid | |
./bin/rake db:migrate | |
./bin/rails s -b 0.0.0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment