Skip to content

Commit 8d6bf9e

Browse files
committed
Add circleci
1 parent bade48c commit 8d6bf9e

File tree

11 files changed

+487
-16
lines changed

11 files changed

+487
-16
lines changed

.circleci/config.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker: # use the docker executor type
5+
- image: circleci/ruby:2.6.3
6+
environment:
7+
PGHOST: localhost
8+
PGUSER: tutor_virtual
9+
RAILS_ENV: test
10+
BUNDLER_VERSION: 2.0.1
11+
12+
- image: postgres:11.5-alpine
13+
environment:
14+
POSTGRES_USER: tutor_virtual
15+
POSTGRES_DB: tutor_virtual
16+
POSTGRES_PASSWORD: ""
17+
18+
steps:
19+
- checkout
20+
# Restore Cached Dependencies
21+
- type: cache-restore
22+
name: Restore bundle cache
23+
key: tutor_virtual-{{ checksum "Gemfile.lock" }}
24+
25+
- run: gem install bundler:${BUNDLER_VERSION}
26+
27+
# Caching Ruby Gems
28+
# Reference: https://www.benpickles.com/articles/76-better-ruby-gem-caching-on-circleci
29+
- restore_cache:
30+
keys:
31+
- bundler-{{ checksum "Gemfile.lock" }}
32+
- bundler-
33+
34+
- run: bundle install --clean --path vendor/bundle
35+
36+
- save_cache:
37+
key: bundler-{{ checksum "Gemfile.lock" }}
38+
paths:
39+
- vendor/bundle
40+
41+
# Cache Dependencies
42+
- type: cache-save
43+
name: Store bundle cache
44+
key: tutor_virtual-{{ checksum "Gemfile.lock" }}
45+
paths:
46+
- vendor/bundle
47+
48+
# # Bundle install dependencies
49+
- run: bundle install
50+
51+
# Wait for DB
52+
- run: dockerize -wait tcp://localhost:5432 -timeout 1m
53+
54+
- run: rake db:create # creates the database
55+
- run: rake db:migrate
56+
57+
# Run the tests
58+
- run: rake test
59+
60+
build_release:
61+
docker: # use the docker executor type
62+
- image: docker:stable-git # the primary container, where the job's commands are run
63+
steps:
64+
- checkout # check out the code in the project directory
65+
# A remote environment will be created, and your current primary container
66+
# will be configured to use it.
67+
# Then, any docker-related commands you use will be safely executed in this new environment.
68+
- setup_remote_docker:
69+
docker_layer_caching: true # Enables Docker Layer Caching here to speed up image building
70+
- run: apk add make # Add MAKE in order to get the version from trendlit's Makefile
71+
- run: docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
72+
- run: sh 'bin/docker_build.sh'
73+
- run: sh 'bin/docker_check.sh'
74+
- run: sh 'bin/docker_push.sh'
75+
# Heroku deploy
76+
- run: docker login --username=_ --password=${HEROKU_TOKEN} registry.heroku.com
77+
78+
workflows:
79+
version: 2
80+
test_and_build_release:
81+
jobs:
82+
- test
83+
- build_release:
84+
requires:
85+
- test
86+
filters:
87+
branches:
88+
only: master

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@
3636
#Ignore backup Makefile
3737
*-e
3838
.env
39+
40+
vendor/

Dockerfile

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# References:
2+
# https://iridakos.com/tutorials/2019/04/07/dockerizing-a-rails-application.html
3+
# https://blog.codeship.com/running-rails-development-environment-docker/
4+
5+
# Step 1: Use the official Ruby 2.6.3 Slim Strech image as base:
6+
FROM ruby:2.6.3-slim-stretch AS runtime
7+
8+
# Step 2: We'll set the MALLOC_ARENA_MAX for optimization purposes & prevent memory bloat
9+
# https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html
10+
ENV MALLOC_ARENA_MAX="2"
11+
12+
# Step 3: We'll set '/usr/src' path as the working directory:
13+
# NOTE: This is a Linux "standard" practice - see:
14+
# - http://www.pathname.com/fhs/2.2/
15+
# - http://www.pathname.com/fhs/2.2/fhs-4.1.html
16+
# - http://www.pathname.com/fhs/2.2/fhs-4.12.html
17+
WORKDIR /usr/src
18+
19+
# Step 4: We'll set the working dir as HOME and add the app's binaries path to
20+
# $PATH:
21+
ENV HOME=/usr/src PATH=/usr/src/bin:$PATH
22+
23+
# Step 5: We'll install curl for later dependencies installations
24+
RUN apt-get update && \
25+
apt-get install -y --no-install-recommends \
26+
curl
27+
28+
# Step 6: Add nodejs source
29+
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
30+
31+
# Step 7: Add yarn packages repository
32+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
33+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
34+
35+
# Step 8: Install the common runtime dependencies:
36+
RUN apt-get update && \
37+
apt-get install -y --no-install-recommends \
38+
apt-transport-https software-properties-common \
39+
ca-certificates \
40+
libpq5 \
41+
openssl \
42+
nodejs \
43+
tzdata \
44+
yarn && \
45+
rm -rf /var/lib/apt/lists/*
46+
47+
# Step 9: Start off from the "runtime" stage:
48+
FROM runtime AS development
49+
50+
# Step 10: Install the development dependency packages with alpine package
51+
# manager:
52+
RUN apt-get update && \
53+
apt-get install -y --no-install-recommends \
54+
build-essential \
55+
libpq-dev && \
56+
rm -rf /var/lib/apt/lists/*
57+
58+
# Step 11: Copy the project's Gemfile + lock:
59+
ADD Gemfile* /usr/src/
60+
61+
# Step 12: Install bundler ~2.0
62+
RUN gem install bundler -v 2.0.1
63+
64+
# Step 13: Install the current project gems - they can be safely changed later
65+
# during development via `bundle install` or `bundle update`:
66+
RUN bundle install --jobs=20 --retry=5
67+
68+
# Step 14: Set the default command:
69+
CMD [ "rails", "server", "-b", "0.0.0.0" ]
70+
71+
# Step 15: Add the current directory
72+
ADD . /usr/src
73+
74+
# Step 16: Install Yarn packages:
75+
RUN yarn install
76+
77+
# Step 17: Start off from the development stage image:
78+
FROM development AS builder
79+
80+
# Step 18: Precompile assets:
81+
RUN export DATABASE_URL=postgres://[email protected]:5432/fakedb \
82+
SECRET_KEY_BASE=10167c7f7654ed02b3557b05b88ece \
83+
RAILS_ENV=production && \
84+
rails assets:precompile && \
85+
rails secret > /dev/null
86+
87+
# Step 19: Remove installed gems that belong to the development & test groups -
88+
# we'll copy the remaining system gems into the deployable image on the next
89+
# stage:
90+
RUN bundle config without development:test && bundle clean
91+
92+
# Step 20: Remove files not used on release image:
93+
RUN rm -rf \
94+
bin/setup \
95+
bin/update \
96+
entrypoint.sh \
97+
config/spring.rb \
98+
node_modules \
99+
spec \
100+
tmp/*
101+
102+
# V: Release stage: ============================================================
103+
# In this stage, we build the final, deployable Docker image, which will be
104+
# smaller than the images generated on previous stages:
105+
106+
# Step 21: Start off from the runtime stage image:
107+
FROM runtime AS release
108+
109+
# Step 22: Copy the remaining installed gems from the "builder" stage:
110+
COPY --from=builder /usr/local/bundle /usr/local/bundle
111+
112+
# Step 23: Copy from app code from the "builder" stage, which at this point
113+
# should have the assets from the asset pipeline already compiled:
114+
COPY --from=builder /usr/src /usr/src
115+
116+
# Step 24: Set the RAILS/RACK_ENV and PORT default values:
117+
ENV RAILS_ENV=production RACK_ENV=production PORT=3000
118+
119+
# Step 25: Generate the temporary directories in case they don't already exist:
120+
RUN mkdir -p /usr/src/tmp/cache && \
121+
mkdir -p /usr/src/tmp/pids && \
122+
mkdir -p /usr/src/tmp/sockets && \
123+
chown -R nobody /usr/src
124+
125+
# Step 26: Set the container user to 'nobody':
126+
USER nobody
127+
128+
# Step 27: Set the default command:
129+
CMD [ "puma" ]

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ GEM
7373
execjs
7474
coffee-script-source (1.12.2)
7575
concurrent-ruby (1.1.5)
76-
crass (1.0.4)
76+
crass (1.0.5)
7777
devise (4.7.1)
7878
bcrypt (~> 3.0)
7979
orm_adapter (~> 0.1)

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
APP=tutor_virtual
2+
PROJECT=github.com/ProyectoIntegrador2018/tutor_virtual
3+
RELEASE?=0.0.1
4+
5+
COMMIT?=$(shell git rev-parse HEAD)
6+
BUILD_TIME?=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
7+
8+
.DEFAULT_GOAL := help
9+
10+
build:## Spins that beautiful container!
11+
@./bin/docker_build.sh
12+
13+
bump:## Bumps version
14+
@./bin/bump_version.sh
15+
16+
check:## Check if the tag that is going to be pushed is unique. In other words, if RELEASE variable was updated in the Makefile.
17+
@./bin/docker_check.sh
18+
19+
help: ##Show this help.
20+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
21+
22+
23+
prod:##prod: Run latest built simulating a production env.
24+
@echo 'Prod triggered'
25+
@./bin/docker_run_local_production.sh
26+
27+
##push: push docker image to docker hub
28+
push: check
29+
@./bin/docker_push.sh
30+
31+
rmi:## Removes docker image
32+
@./bin/docker_rmi.sh
33+
34+
run:## Run latest built
35+
@echo 'Run triggered'
36+
@./bin/docker_run.sh
37+
38+
test: ##Run all automated tests.
39+
@echo 'Test triggered'
40+
41+
version: ##Prints current version
42+
@echo -n ${RELEASE}
43+
@echo

README.md

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,95 @@
1-
# README
1+
# Tutor Virtual
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
3+
[![Maintainability](https://api.codeclimate.com/v1/badges/ba4ca1e8e93e5cef25d7/maintainability)](https://codeclimate.com/github/ProyectoIntegrador2018/tutor_virtual/maintainability)
54

6-
Things you may want to cover:
5+
El sistema tiene como objetivo el automatizar los procesos que lleva a cabo nuestra cliente, Dora Elizabeth García Olivier, perteneciente del Centro Virtual de Aprendizajes. Dentro de sus actividades que actualmente realiza de manera manual se incluyen el: Dar de alta a alumnos, profesores y directivos asociados al servicio social Aprendizaje Verde.
76

8-
* Ruby version
7+
## Tabla de contenidos
98

10-
* System dependencies
9+
* TBD
1110

12-
* Configuration
11+
## Detalles del Cliente
1312

14-
* Database creation
13+
| Nombre | Email | Rol |
14+
| ------------------- | ------------------- | ---------------- |
15+
| Dora García Olivier | [email protected] | Coordinador CVA |
1516

16-
* Database initialization
1717

18-
* How to run the test suite
18+
## Ambientes del Sistema
1919

20-
* Services (job queues, cache servers, search engines, etc.)
20+
* **Producción** - [TutorVirtual](http://tutorvirtual.herokuapp.com/)
21+
* **Desarrollo** - [Dev-TutorVirtual](http://dev-tutorvirtual.herokuapp.com/)
2122

22-
* Deployment instructions
23+
Equipo: AD 2019
2324

24-
* ...
25+
| Nombre | Email | Rol |
26+
| ------------------ | ------------------ | ------------ |
27+
| Sergio Diaz | [email protected] | Scrum Master |
28+
| Patricio Forbes | [email protected] | PO Proxy |
29+
| Arturo González | [email protected] | Desarrollo |
30+
31+
## Herramientas
32+
33+
Pide acceso a las siguientes herramientas de no ser que no lo tengas:
34+
35+
* [Github repo](https://github.com/ProyectoIntegrador2018/tutor_virtual)
36+
* [Backlog](https://github.com/ProyectoIntegrador2018/tutor_virtual/projects/2)
37+
* [Documentation](https://drive.google.com/drive/folders/16hcLTaW8YtWHzEUo9VfwR-Qjewcsap-G?usp=sharing)
38+
39+
## Configuración del proyecto
40+
41+
### Pre-condiciones
42+
- Install docker and docker-compose.
43+
44+
45+
### Build and Run
46+
47+
EL siguiente comando usa un multi-stage build para usar compilaciones de
48+
varias etapas, y levantar la aplicación con un solo comando:
49+
50+
```
51+
docker-compose up web
52+
```
53+
54+
### Test
55+
56+
EL siguiente comando usa un multi-stage build para usar compilaciones de
57+
varias etapas, y levantar la aplicación en el ambiente de ```test``` con un
58+
solo comando:
59+
60+
```
61+
docker-compose run --rm test bash
62+
```
63+
64+
65+
El comando anterior construirá la imagen si no existe, llamada: `proyecto_integrador / tutor_virtual: development`.
66+
67+
### Debbuging
68+
La estructura del proyecto permite a cualquiera ejecutar fácilmente una consola
69+
de bash para poder ejecutar cualquier tipo de instrucción. Por ejemplo algo como ```rails db:create```, ```rails db:migrate```, o ```rails db:seed```
70+
71+
72+
```
73+
docker-compose run --rm web bash
74+
```
75+
76+
### Pruebas
77+
Si se ejecuta ```rails db:seed```, se agregarán dos usuarios de prueba a la base
78+
de datos. Uno con permisos normales y otro con permisos de administrador.
79+
```
80+
81+
password: 123456
82+
83+
84+
password: 123456
85+
86+
```
87+
## Stack Tecnológico
88+
89+
### Librerías Front End:
90+
* Jquery
91+
* CSS
92+
93+
### Librerías Back End:
94+
95+
* Ruby on Rails

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ApplicationController < ActionController::Base
2-
before_action :require_login
2+
33
private
44

55
def require_login

0 commit comments

Comments
 (0)