add docker setup
This commit is contained in:
1
.tool-versions
Normal file
1
.tool-versions
Normal file
@@ -0,0 +1 @@
|
||||
ruby 3.1.1
|
||||
45
Dockerfile
Normal file
45
Dockerfile
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
41
docker-compose.yml
Normal file
41
docker-compose.yml
Normal file
@@ -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:
|
||||
25
scripts/setup
Executable file
25
scripts/setup
Executable file
@@ -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!'
|
||||
0
scripts/start
Normal file
0
scripts/start
Normal file
Reference in New Issue
Block a user