Skip to content

Commit 83937d0

Browse files
committed
added dockerized dev and deployment
1 parent fff0472 commit 83937d0

10 files changed

+192
-17
lines changed

.gitlab-ci.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
stages:
2+
- release
3+
- deploy-production
4+
5+
before_script:
6+
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
7+
8+
variables:
9+
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
10+
11+
release:
12+
stage: release
13+
script:
14+
- chmod +x create_env.sh
15+
- "sh ./create_env.sh"
16+
- docker build --pull -t $CONTAINER_RELEASE_IMAGE ./ -f ./Dockerfile.release
17+
- docker push $CONTAINER_RELEASE_IMAGE
18+
only:
19+
- develop
20+
- master
21+
tags:
22+
- build #shared runner on shared machine
23+
24+
deploy-production-de:
25+
stage: deploy-production
26+
only:
27+
- master
28+
script:
29+
- docker pull $CONTAINER_RELEASE_IMAGE
30+
- chmod +x dbauth.sh
31+
- "sh ./dbauth.sh"
32+
- docker-compose -f docker-compose.production.yml up -d postgres
33+
- docker-compose -f docker-compose.production.yml exec -d postgres sh /usr/bin/setpw.sh
34+
- sleep 10 #make sure postgres container is ready
35+
- docker-compose -f docker-compose.production.yml run --rm rails bundle exec rake db:create
36+
- docker-compose -f docker-compose.production.yml run --rm rails bundle exec rake db:migrate
37+
- docker-compose -f docker-compose.production.yml up -d rails
38+
tags:
39+
- production-do-de-1
40+
41+
deploy-production-us:
42+
stage: deploy-production
43+
only:
44+
- master
45+
script:
46+
- docker pull $CONTAINER_RELEASE_IMAGE
47+
- chmod +x dbauth.sh
48+
- "sh ./dbauth.sh"
49+
- docker-compose -f docker-compose.production.yml up -d postgres
50+
- docker-compose -f docker-compose.production.yml exec -d postgres sh /usr/bin/setpw.sh
51+
- sleep 10 #make sure postgres container is ready
52+
- docker-compose -f docker-compose.production.yml run --rm rails bundle exec rake db:create
53+
- docker-compose -f docker-compose.production.yml run --rm rails bundle exec rake db:migrate
54+
- docker-compose -f docker-compose.production.yml up -d rails
55+
tags:
56+
- production-do-us-1
57+
58+
deploy-production-singapore-1:
59+
stage: deploy-production
60+
only:
61+
- master
62+
script:
63+
- docker pull $CONTAINER_RELEASE_IMAGE
64+
- chmod +x dbauth.sh
65+
- "sh ./dbauth.sh"
66+
- docker-compose -f docker-compose.production.yml up -d postgres
67+
- docker-compose -f docker-compose.production.yml exec -d postgres sh /usr/bin/setpw.sh
68+
- sleep 10 #make sure postgres container is ready
69+
- docker-compose -f docker-compose.production.yml run --rm rails bundle exec rake db:create
70+
- docker-compose -f docker-compose.production.yml run --rm rails bundle exec rake db:migrate
71+
- docker-compose -f docker-compose.production.yml up -d rails
72+
tags:
73+
- production-do-singapore-1

Dockerfile.dev

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM registry.gitlab.com/basemate-ops/workflow/dev:latest

Dockerfile.release

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM registry.gitlab.com/basemate-ops/workflow/release:latest

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ ruby '2.6.5'
55

66
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
77
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
8-
# Use sqlite3 as the database for Active Record
9-
gem 'sqlite3', '~> 1.4'
8+
# Use postgres as the database for Active Record
9+
gem 'pg'
1010
# Use Puma as the app server
1111
gem 'puma', '~> 4.1'
1212
# Use SCSS for stylesheets

config/database.yml

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
# SQLite. Versions 3.8.0 and up are supported.
2-
# gem install sqlite3
3-
#
4-
# Ensure the SQLite 3 gem is defined in your Gemfile
5-
# gem 'sqlite3'
6-
#
71
default: &default
8-
adapter: sqlite3
2+
adapter: postgresql
3+
encoding: unicode
4+
host: postgres
5+
username: <%= ENV.fetch("POSTGRES_USER") { "postgres" } %>
6+
password: <%= ENV.fetch("POSTGRES_PASSWORD") { "postgres" } %>
97
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10-
timeout: 5000
8+
9+
test:
10+
<<: *default
11+
database: test
1112

1213
development:
1314
<<: *default
14-
database: db/development.sqlite3
15+
database: development
1516

16-
# Warning: The database defined as "test" will be erased and
17-
# re-generated from your development database when you run "rake".
18-
# Do not set this db to the same as development or production.
19-
test:
17+
staging:
2018
<<: *default
21-
database: db/test.sqlite3
19+
database: staging
2220

2321
production:
2422
<<: *default
25-
database: db/production.sqlite3
23+
database: production

config/secrets.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
production:
2+
secret_key_base: <%= ENV.fetch("SECRET_KEY_BASE") { "" } %>

create_env.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo "" >> ./.env
2+
echo "SECRET_KEY_BASE=$SECRET_KEY_BASE" >> ./.env
3+
echo "MAILER_ADDRESS=$MAILER_ADDRESS" >> ./.env
4+
echo "MAILER_DOMAIN=$MAILER_DOMAIN" >> ./.env
5+
echo "MAILER_PASSWORD=$MAILER_PASSWORD" >> ./.env
6+
echo "MAILER_USER=$MAILER_USER" >> ./.env

dbauth.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
if [ ! -f ./.env ]
3+
then
4+
POSTGRES_USER="postgres"
5+
POSTGRES_PASSWORD=$(openssl rand -base64 16)
6+
echo "POSTGRES_USER=$POSTGRES_USER" >> ./.env
7+
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> ./.env
8+
fi

docker-compose.production.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3'
2+
services:
3+
4+
postgres:
5+
image: registry.gitlab.com/basemate-ops/workflow/postgres
6+
expose:
7+
- 5432
8+
volumes:
9+
- data-volume:/var/lib/postgresql/data
10+
environment:
11+
POSTGRES_DB: "production"
12+
env_file:
13+
- ./.env
14+
15+
rails:
16+
image: registry.gitlab.com/matestack/matestack-ui-bootstrap
17+
ports:
18+
- "3003:3000"
19+
links:
20+
- postgres
21+
- redis
22+
environment:
23+
RAILS_ENV: "production"
24+
POSTGRES_DB: "production"
25+
SECRET_KEY_BASE: $SECRET_KEY_BASE
26+
MAILER_ADDRESS: $MAILER_ADDRESS
27+
MAILER_DOMAIN: $MAILER_DOMAIN
28+
MAILER_PASSWORD: $MAILER_PASSWORD
29+
MAILER_USER: $MAILER_USER
30+
env_file:
31+
- ./.env
32+
command: "bundle exec rails server --binding 0.0.0.0 --port 3000"
33+
34+
redis:
35+
restart: always
36+
image: redis:5.0.7-alpine
37+
volumes:
38+
- redis-volume:/data
39+
40+
41+
volumes:
42+
data-volume:
43+
redis-volume:

docker-compose.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3'
2+
services:
3+
4+
postgres:
5+
image: registry.gitlab.com/basemate-ops/workflow/postgres
6+
expose:
7+
- 5432
8+
volumes:
9+
- data-volume:/var/lib/postgresql/data
10+
environment:
11+
POSTGRES_USER: postgres
12+
POSTGRES_PASSWORD: postgres
13+
POSTGRES_DB: development
14+
15+
rails:
16+
build:
17+
context: .
18+
dockerfile: ./Dockerfile.dev
19+
ports:
20+
- "3000:3000"
21+
links:
22+
- postgres
23+
- redis
24+
environment:
25+
RAILS_ENV: "development"
26+
POSTGRES_DB: "development"
27+
volumes:
28+
- ./:/app
29+
- gem-volume:/usr/local/bundle
30+
- node-volume:/app/node_modules
31+
command: "bundle exec rails server --binding 0.0.0.0 --port 3000"
32+
33+
redis:
34+
restart: always
35+
image: redis:5.0.7-alpine
36+
volumes:
37+
- redis-volume:/data
38+
39+
volumes:
40+
data-volume:
41+
gem-volume:
42+
node-volume:
43+
redis-volume:

0 commit comments

Comments
 (0)