diff --git a/.dockerignore b/.dockerignore index 9612375..9be59ed 100644 --- a/.dockerignore +++ b/.dockerignore @@ -35,3 +35,4 @@ /app/assets/builds/* !/app/assets/builds/.keep /public/assets +.docker-compose.yml \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..dbb61bc --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,42 @@ +# syntax = docker/dockerfile:1 + +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile +ARG RUBY_VERSION=3.3.5 +FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base + +# Rails app lives here +WORKDIR /rails + +RUN apt-get update && apt-get install -y nodejs + +FROM base as build + +# Install packages needed to build gems +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config + +# Install application gems +COPY Gemfile Gemfile.lock ./ +RUN bundle install + +# Copy application code +COPY . . + +# Final stage for app image +FROM base + +# Install packages needed for deployment +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y curl libvips postgresql-client && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Copy built artifacts: gems, application +COPY --from=build /usr/local/bundle /usr/local/bundle +COPY --from=build /rails /rails + +# Entrypoint prepares the database. +ENTRYPOINT ["/rails/bin/docker-entrypoint"] + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3001 +CMD ["./bin/rails", "server", "--binding=0.0.0.0"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..97fa122 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +services: + backend: + build: + context: . + dockerfile: Dockerfile.dev + ports: + - "3001:3001" + depends_on: + - db + environment: + DATABASE_URL: postgres://postgres:postgres@db:5432/postgres + RAILS_ENV: development + PORT: 3001 + frontend: + build: ../wedding-planner-frontend + ports: + - 3000:3000 + depends_on: + - backend + nginx: + image: nginx:latest + ports: + - 80:80 + volumes: + - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro + depends_on: + - frontend + - backend + db: + image: postgres:17 + ports: + - 5432 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + + \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index 9fb17cc..f8a4fac 100644 --- a/nginx.conf +++ b/nginx.conf @@ -3,12 +3,12 @@ server { server_name libre-wedding-planner.app.localhost; location /api/ { - proxy_pass http://localhost:3001/; + proxy_pass http://backend:3001/; proxy_set_header Host $http_host; } location / { - proxy_pass http://localhost:3000; + proxy_pass http://frontend:3000; proxy_set_header Host $http_host; } }