Skip to content

Commit

Permalink
WIP setting up docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
croyfish committed Sep 25, 2024
1 parent 6fd941f commit 6ec3f85
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 46 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ yarn-debug.log*

/app/assets/builds/*
!/app/assets/builds/.keep

# Ignore VIM swapfiles
*.swo
*.swp
78 changes: 36 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 6ec3f85

Please sign in to comment.