diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a01b0e5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.vscode +README.md \ No newline at end of file diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..1266fcf --- /dev/null +++ b/.env.dev @@ -0,0 +1,7 @@ +RAILS_ENV=development +HOST=0.0.0.0 +PORT=3000 + +DATABASE_NAME=url_shortener +DATABASE_USER=user +DATABASE_PASSWORD=user_12345 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..37eb5ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +/node_modules +/yarn-error.log + +/public/assets +.byebug_history diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..962f692 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,29 @@ + +FROM ruby:2.6.6-alpine + +ENV APP_PATH /usr/src/app +ENV BUNDLE_VERSION 2.1.4 +ENV BUNDLE_PATH /usr/local/bundle/gems +ENV RAILS_LOG_TO_STDOUT true +ENV RAILS_PORT 3000 + +WORKDIR $APP_PATH + +EXPOSE $RAILS_PORT + +RUN apk -U add --no-cache \ +build-base \ +postgresql-dev \ +postgresql-client \ +tzdata \ +yarn + +COPY ./entrypoint.dev.sh /usr/bin/entrypoint.sh +RUN chmod +x /usr/bin/entrypoint.sh + +RUN gem install bundler --version "$BUNDLE_VERSION" +RUN gem install rubocop + +COPY . . + +ENTRYPOINT ["entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f9f12ae --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3' + +services: + db: + image: postgres:12.5-alpine + volumes: + - db_data:/var/lib/postgresql/data + environment: + POSTGRES_USER: user + POSTGRES_PASSWORD: user_12345 + POSTGRES_DB: url_shortener + ports: + - 5432:5432 + app: + build: + context: . + dockerfile: Dockerfile.dev + volumes: + - .:/usr/src/app + - gem_cache:/usr/local/bundle/gems + command: bundle exec rails s -p 3000 -b '0.0.0.0' + stdin_open: true + tty: true + env_file: .env.dev + ports: + - 3000:3000 + depends_on: + - db +volumes: + gem_cache: + db_data: \ No newline at end of file diff --git a/entrypoint.dev.sh b/entrypoint.dev.sh new file mode 100644 index 0000000..0cfd33e --- /dev/null +++ b/entrypoint.dev.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e +echo "Environment: $RAILS_ENV" + +bundle check || bundle install --jobs 20 --retry 5 + +rm -f $APP_PATH/tmp/pids/server.pid + +${@} \ No newline at end of file