Merge pull request #29 from turniere/ticket/TURNIERE-108

Create Dockerfile and Docker Rake tasks
This commit is contained in:
Daniel Schädler 2019-04-17 09:19:10 +02:00 committed by GitHub
commit 9c808b9921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 0 deletions

11
.dockerignore Normal file
View File

@ -0,0 +1,11 @@
.git
test/**
spec/**
tmp/**
.gitignore
.hound.yml
.rspec
.rubocop.yml
.travis-yml
docker-compose.yml
README.md

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM ruby:2.6.2-alpine
RUN apk add build-base tzdata sqlite sqlite-dev && gem install tzinfo-data
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install --deployment --without development test
COPY . /app
ENV RAILS_ENV production
CMD bundle exec rails db:migrate && bundle exec rails s -p 3000 -b 0.0.0.0

6
docker-compose.yml Normal file
View File

@ -0,0 +1,6 @@
version: "3"
services:
app:
image: turniere/backend
ports:
- 3000:3000

28
lib/tasks/docker.rake Normal file
View File

@ -0,0 +1,28 @@
# frozen_string_literal: true
IMAGE_NAME = 'turniere/backend'
namespace :docker do
desc 'Build docker image'
task :build, [:tag] do |_, args|
args.with_defaults(tag: 'latest')
sh "docker build -t #{IMAGE_NAME}:#{args.tag} ."
end
desc 'Tag docker image with Travis build number'
task :tag do
next if ENV['TRAVIS_PULL_REQUEST'] != 'false'
tag = "build#{ENV['TRAVIS_BUILD_NUMBER']}"
sh "docker tag #{IMAGE_NAME} #{IMAGE_NAME}:#{tag}"
end
desc 'Push docker image'
task :push do
sh "docker push #{IMAGE_NAME}"
end
desc 'Run TravisCI tasks'
task travis: %i[build tag push] do
end
end