From fb156eef7ef7252247bb2cd6da6add947169b4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Geonizeli?= Date: Mon, 28 Feb 2022 17:33:13 -0300 Subject: [PATCH] add docker setup --- .tool-versions | 1 + Dockerfile | 45 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 6 ++++++ docker-compose.yml | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/setup | 25 +++++++++++++++++++++++++ scripts/start | 0 6 files changed, 118 insertions(+) create mode 100644 .tool-versions create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 scripts/setup create mode 100644 scripts/start diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..e7f4c11 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 3.1.1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e69a440 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM ruby:3.1.1-alpine + +ENV APP_PATH /posterr/ +ENV APP_USER posterr +ENV APP_USER_HOME /home/posterr + +ENV BUNDLE_PATH $APP_USER_HOME +ENV GEM_HOME $APP_USER_HOME/bundle +ENV BUNDLE_BIN $GEM_HOME/bin + +ENV RAILS_LOG_TO_STDOUT=true +ENV TZ=America/Sao_Paulo + +ENV PATH $PATH:$BUNDLE_BIN + +# Puma +EXPOSE 3000 + +ARG UID +RUN : "${UID:?You must provide a UID argument when building this image.}" + +RUN adduser -h $APP_USER_HOME -D -u $UID $APP_USER + +WORKDIR $APP_PATH + +COPY Gemfile* $APP_PATH + +# The package shared-mime-info is required in a Rails dependency +RUN apk update && \ + apk add --no-cache \ + git \ + build-base \ + postgresql-dev \ + tzdata \ + less \ + shared-mime-info && \ + bundle config jobs $(nproc --all) && \ + bundle install && \ + chown -R $APP_USER:$APP_USER $APP_USER_HOME && \ + chown -R $APP_USER:$APP_USER $APP_PATH && \ + rm -r /var/cache/apk/* + +COPY --chown=posterr . $APP_PATH + +USER $APP_USER diff --git a/README.md b/README.md index 263a396..a4e6193 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # README +## Setup + 1. Run setup script (docker) `./scripts/setup` + 2. Execute seeds rake with `docker-compose run --rm web rails db:seed` + 3. Start project with `docker-compose up` + 4. Seed routes documentation `http://localhost:3000/rails/info/routes` + ## Planning ### Question for the Product Manager diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..081934e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +version: "3.6" + +services: + web: + image: strider-posterr + volumes: + - .:/posterr:delegated + - gems:/home/posterr:delegated + environment: + - DATABASE_URL=postgres://postgres:postgres@db:5432 + depends_on: + - db + + container_name: strider-posterr-web + command: > + sh -c ' + bundle check || bundle install && + rm -f tmp/pids/server.pid && + rails s -b 0.0.0.0' + ports: + - "3000:3000" + + db: + image: postgres:11-alpine + container_name: strider-posterr-db + volumes: + - pg-data:/var/lib/postgresql/data:delegated + - ./scripts:/scripts:delegated + - ./tmp:/tmp:delegated + ports: + - "5435:5432" + + gems: + image: busybox:latest + container_name: strider-posterr-gems + volumes: + - /gems + +volumes: + gems: + pg-data: diff --git a/scripts/setup b/scripts/setup new file mode 100755 index 0000000..22b2eb3 --- /dev/null +++ b/scripts/setup @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -e + +cd $(dirname $(dirname $0)) + +yellow_text(){ + echo "`tput setaf 3`$@`tput sgr0`" +} + +green_text(){ + echo "`tput setaf 2`$@`tput sgr0`" +} + +if [ -f Dockerfile ]; then + docker build --build-arg UID=$UID -t strider-posterr . +else + red_text 'Could not find Dockerfile. Please run this script from the root of the project.' + return +fi + +yellow_text 'Preparing the database...' +docker-compose run --rm web rails db:create db:migrate + +green_text 'Everything ready to run!' diff --git a/scripts/start b/scripts/start new file mode 100644 index 0000000..e69de29