diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6cbf964 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +test/** +spec/** +tmp/** +.gitignore +.hound.yml +.rspec +.rubocop.yml +.travis-yml +docker-compose.yml +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5af2fc2 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5a0d907 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3" +services: + app: + image: turniere/backend + ports: + - 3000:3000 diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake new file mode 100644 index 0000000..a4c97e7 --- /dev/null +++ b/lib/tasks/docker.rake @@ -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