add docker setup
This commit is contained in:
58
Dockerfile
Normal file
58
Dockerfile
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
FROM ruby:3.1.2-alpine
|
||||||
|
|
||||||
|
# App variables
|
||||||
|
ENV APP_PATH /progress-test/
|
||||||
|
ENV APP_USER progress-test
|
||||||
|
ENV APP_USER_HOME /home/progress-test
|
||||||
|
# Bundler variables
|
||||||
|
ENV BUNDLE_PATH $APP_USER_HOME
|
||||||
|
ENV GEM_HOME $APP_USER_HOME/bundle
|
||||||
|
ENV BUNDLE_BIN $GEM_HOME/bin
|
||||||
|
# Rails variables
|
||||||
|
ENV RAILS_LOG_TO_STDOUT=true
|
||||||
|
# System variables
|
||||||
|
ENV PATH $PATH:$BUNDLE_BIN
|
||||||
|
# Timezone
|
||||||
|
ENV TZ=America/Sao_Paulo
|
||||||
|
|
||||||
|
# Puma
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# UID of the user that will be created
|
||||||
|
ARG UID
|
||||||
|
|
||||||
|
# Validating if UID argument was provided
|
||||||
|
RUN : "${UID:?You must provide a UID argument when building this image.}"
|
||||||
|
|
||||||
|
# Creating an user so we don't run everything as root
|
||||||
|
RUN adduser -h $APP_USER_HOME -D -u $UID $APP_USER
|
||||||
|
|
||||||
|
# cd to $APP_PATH
|
||||||
|
WORKDIR $APP_PATH
|
||||||
|
|
||||||
|
COPY Gemfile* package.json yarn.lock $APP_PATH
|
||||||
|
|
||||||
|
# Installing libraries and gems
|
||||||
|
# The package shared-mime-info is required in a Rails dependency
|
||||||
|
# shared-mime-info ref: https://vtex.slack.com/archives/CE16Q9XRT/p1616716948056900
|
||||||
|
RUN apk update && \
|
||||||
|
apk add --no-cache \
|
||||||
|
git \
|
||||||
|
build-base \
|
||||||
|
postgresql-dev \
|
||||||
|
tzdata \
|
||||||
|
nodejs \
|
||||||
|
yarn \
|
||||||
|
less \
|
||||||
|
graphviz \
|
||||||
|
shared-mime-info && \
|
||||||
|
bundle config jobs $(nproc --all) && \
|
||||||
|
bundle install && \
|
||||||
|
yarn && \
|
||||||
|
chown -R $APP_USER:$APP_USER $APP_USER_HOME && \
|
||||||
|
chown -R $APP_USER:$APP_USER $APP_PATH && \
|
||||||
|
rm -r /var/cache/apk/*
|
||||||
|
|
||||||
|
COPY --chown=progress-test . $APP_PATH
|
||||||
|
|
||||||
|
USER $APP_USER
|
||||||
28
README.md
28
README.md
@@ -1,24 +1,6 @@
|
|||||||
# README
|
# Requisitos
|
||||||
|
- Docker
|
||||||
|
- docker-compose
|
||||||
|
|
||||||
This README would normally document whatever steps are necessary to get the
|
# Setup
|
||||||
application up and running.
|
- Executar no terminal: './scripts/setup'
|
||||||
|
|
||||||
Things you may want to cover:
|
|
||||||
|
|
||||||
* Ruby version
|
|
||||||
|
|
||||||
* System dependencies
|
|
||||||
|
|
||||||
* Configuration
|
|
||||||
|
|
||||||
* Database creation
|
|
||||||
|
|
||||||
* Database initialization
|
|
||||||
|
|
||||||
* How to run the test suite
|
|
||||||
|
|
||||||
* Services (job queues, cache servers, search engines, etc.)
|
|
||||||
|
|
||||||
* Deployment instructions
|
|
||||||
|
|
||||||
* ...
|
|
||||||
44
docker-compose.yml
Normal file
44
docker-compose.yml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
version: "3.6"
|
||||||
|
|
||||||
|
x-rails: &rails
|
||||||
|
image: progress-test
|
||||||
|
volumes:
|
||||||
|
- .:/progress-test:delegated
|
||||||
|
- gems:/home/progress-test:delegated
|
||||||
|
environment:
|
||||||
|
- DISABLE_SPRING=1
|
||||||
|
- DATABASE_URL=postgres://postgres:postgres@db:5432
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
<<: *rails
|
||||||
|
container_name: progress-test-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.3-alpine
|
||||||
|
container_name: progress-test-db
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data:delegated
|
||||||
|
- ./scripts:/scripts:delegated
|
||||||
|
- ./tmp:/tmp:delegated
|
||||||
|
ports:
|
||||||
|
- "5435:5432"
|
||||||
|
|
||||||
|
gems:
|
||||||
|
image: busybox:latest
|
||||||
|
container_name: progress-test-gems
|
||||||
|
volumes:
|
||||||
|
- /gems
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
gems:
|
||||||
|
pg-data:
|
||||||
51
scripts/setup
Executable file
51
scripts/setup
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/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`"
|
||||||
|
}
|
||||||
|
|
||||||
|
build_docker_image(){
|
||||||
|
if [ -f Dockerfile ]; then
|
||||||
|
docker build --build-arg UID=$UID -t progress-test .
|
||||||
|
else
|
||||||
|
red_text 'Could not find Dockerfile. WTF?'
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################
|
||||||
|
### Build docker image ###
|
||||||
|
##########################
|
||||||
|
|
||||||
|
yellow_text 'Building progress-test image, this might take a while...'
|
||||||
|
|
||||||
|
if [[ $(docker images | grep progress-test) ]]; then
|
||||||
|
green_text 'Found progress-test docker image. Do you want to rebuild it? (y/N)'
|
||||||
|
read build_image
|
||||||
|
|
||||||
|
if [[ $build_image == 'y' ]]; then
|
||||||
|
build_docker_image
|
||||||
|
else
|
||||||
|
yellow_text 'Ok, skipping...'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
build_docker_image
|
||||||
|
fi
|
||||||
|
|
||||||
|
######################
|
||||||
|
### Database setup ###
|
||||||
|
######################
|
||||||
|
|
||||||
|
yellow_text 'Preparing the database...'
|
||||||
|
docker-compose run --rm web rails db:create
|
||||||
|
|
||||||
|
|
||||||
|
green_text 'Everything ready to run!'
|
||||||
Reference in New Issue
Block a user