From 6ec3f85ea168ec0ed8efad9230f335794fcb93ba Mon Sep 17 00:00:00 2001 From: Jeff Croyle Date: Wed, 25 Sep 2024 17:08:50 -0400 Subject: [PATCH] WIP setting up docker compose --- .gitignore | 4 +++ Dockerfile | 78 +++++++++++++++++++++------------------------- docker-compose.yml | 40 ++++++++++++++++++++++++ package.json | 5 +-- 4 files changed, 81 insertions(+), 46 deletions(-) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 31118b498..017675e6b 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,7 @@ yarn-debug.log* /app/assets/builds/* !/app/assets/builds/.keep + +# Ignore VIM swapfiles +*.swo +*.swp diff --git a/Dockerfile b/Dockerfile index 724686cea..a1002b2b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,56 +1,50 @@ -# syntax = docker/dockerfile:1.3 -FROM ruby:2.7.4 AS builder - -# set env vars -ENV APP_HOME /home/app/MyLibraryNYCApp -ENV AWS_DEFAULT_REGION=us-east-1 - -ARG RAILS_ENV -ENV RAILS_ENV=${RAILS_ENV} - +# Set base image and working directory +FROM ruby:2.7.4 + +# Install necessary packages, including curl and PostgreSQL client +RUN apt-get update -qq && apt-get install -y \ + curl \ + postgresql-client \ + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ + && apt-get install -y nodejs \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Yarn globally +RUN npm install -g yarn + +# Set environment variables +ENV RAILS_ENV=development +ENV APP_HOME=/app +RUN mkdir $APP_HOME WORKDIR $APP_HOME -# install packages -RUN apt-get update -qq \ - && apt-get install -y \ - curl \ - postgresql-client \ - git - -RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \ - && apt-get -y install nodejs \ - && npm install --global yarn - -# Install esbuild +# Install esbuild globally RUN npm install -g esbuild -# set up app files -COPY . $APP_HOME -COPY Gemfile $APP_HOME -COPY Gemfile.lock $APP_HOME -WORKDIR $APP_HOME +# Copy Gemfile and Gemfile.lock first +COPY Gemfile Gemfile.lock $APP_HOME/ + +# Install bundler and Ruby dependencies +RUN gem install bundler -v 2.4.22 +RUN bundle install --jobs 30 -## bundle -ENV BUNDLER_VERSION=2.4.22 -RUN gem install bundler -v $BUNDLER_VERSION -RUN bundle config --global github.https true \ - && bundle install --jobs 30 +# Copy package.json and package-lock.json before running yarn install +COPY package.json $APP_HOME/ -COPY package.json $APP_HOME/package.json -COPY package-lock.json $APP_HOME/package-lock.json +# Install JS dependencies RUN yarn install -# build +# Now copy the rest of the application +COPY . $APP_HOME/ + +# Precompile assets RUN yarn build RUN yarn build:css -RUN --mount=type=secret,id=AWS_ACCESS_KEY_ID \ - --mount=type=secret,id=AWS_SECRET_ACCESS_KEY \ - AWS_ACCESS_KEY_ID=$(cat /run/secrets/AWS_ACCESS_KEY_ID) \ - && export AWS_ACCESS_KEY_ID \ - AWS_SECRET_ACCESS_KEY=$(cat /run/secrets/AWS_SECRET_ACCESS_KEY) \ - && export AWS_SECRET_ACCESS_KEY \ - && bundle exe rails assets:precompile +# Expose the app port EXPOSE 3000 + +# Start the server CMD ["bundle", "exec", "rails", "server", "-p", "3000", "-b", "0.0.0.0"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..4648c722e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +services: + web: + build: + context: . + ports: + - "3000:3000" + environment: + - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} + - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} + - RAILS_ENV=development + volumes: + - .:/app + depends_on: + - db + - elasticsearch + command: ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] + + db: + image: postgres:13 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + volumes: + - pgdata:/var/lib/postgresql/data + ports: + - "5432:5432" + + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:6.8.0 + environment: + - discovery.type=single-node + ports: + - "9200:9200" + volumes: + - esdata:/usr/share/elasticsearch/data + +volumes: + pgdata: + esdata: + diff --git a/package.json b/package.json index cc418a16f..d73194ff6 100644 --- a/package.json +++ b/package.json @@ -30,12 +30,11 @@ "mocha": "4.0.1", "nightwatch": "^1.7.8", "nock": "^13.0.11", - "node-sass": "6.0", - "node-sass-glob-importer": "^5.3.2", "nyc": "^13.0.0", "prettier": "2.7.1", "react-addons-test-utils": "15.6.0", "redux-mock-store": "^1.5.4", + "sass": "^1.71.1", "sinon": "4.0.1", "supertest": "^6.1.5", "typescript": "^4.7.4" @@ -98,8 +97,6 @@ "jest-mock-axios": "^4.7.3", "jquery": "^3.6.0", "mini-css-extract-plugin": "^0.9.0", - "node-sass": "6.0", - "node-sass-glob-importer": "^5.3.2", "npm": "^7.20.5", "postcss": "8.4.21", "postcss-flexbugs-fixes": "^5.0.2",