From 4db7b8f3b89beb588d714c61ae4fb0a7159331ff Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Thu, 6 Apr 2023 20:58:58 +0200 Subject: [PATCH] feat: dockerized rails app Signed-off-by: Louis Vallat --- .dockerignore | 4 ++++ .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ .ruby-version | 2 +- Dockerfile | 24 ++++++++++++++++++++++++ Gemfile | 2 +- Gemfile.lock | 13 +++++++++---- 6 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..90d834e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.bundle +node_modules +log +vendor \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..9aa8923 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +image: docker:latest +services: + - docker:dind + +stages: + - release + +variables: + # Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled + DOCKER_HOST: tcp://docker:2376 + DOCKER_TLS_CERTDIR: "/certs" + CONTAINER_BRANCH_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG + CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest + +release: + stage: release + script: + - sed -i "s/__VERSION__/${CI_COMMIT_SHORT_SHA}/" src/_footer.html + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker build . -t $CONTAINER_BRANCH_IMAGE + - docker push $CONTAINER_BRANCH_IMAGE + except: + - master + +release-master: + stage: release + script: + - sed -i "s/__VERSION__/${CI_COMMIT_SHORT_SHA}/" src/_footer.html + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker build . -t $CONTAINER_RELEASE_IMAGE + - docker push $CONTAINER_RELEASE_IMAGE + only: + - master + diff --git a/.ruby-version b/.ruby-version index 316881c..be94e6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.0.5 +3.2.2 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5de5d77 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# syntax=docker/dockerfile:1 +FROM ruby:3.2.2 + +ENV RAILS_ENV=production +ENV RAILS_SERVE_STATIC_FILES=yes +ENV RAILS_LOG_TO_STDOUT=yes +EXPOSE 3000 + +RUN apt-get update && \ + curl -fsSL https://deb.nodesource.com/setup_19.x | bash - && \ + apt-get install -y sqlite3 neovim curl nodejs --no-install-recommends && \ + apt-get clean && \ + bundle config --global frozen 1 && \ + npm install --global yarn + + +WORKDIR /count_anything +COPY Gemfile Gemfile.lock package.json yarn.lock ./ +RUN bundle install --without development test && \ + yarn install + +COPY . . + +CMD /count_anything/bin/rails assets:precompile && /count_anything/bin/rails db:migrate && /count_anything/bin/rails server diff --git a/Gemfile b/Gemfile index 77bdb00..ed977cf 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.0.5" +ruby "3.2.2" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.0.4" diff --git a/Gemfile.lock b/Gemfile.lock index 9df763c..0e9ba69 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,6 +124,7 @@ GEM matrix (0.4.2) method_source (1.0.0) mini_mime (1.1.2) + mini_portile2 (2.8.1) minitest (5.16.3) msgpack (1.6.0) net-imap (0.3.2) @@ -136,7 +137,8 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.8) - nokogiri (1.13.10-x86_64-linux) + nokogiri (1.13.10) + mini_portile2 (~> 2.8.0) racc (~> 1.4) orm_adapter (0.5.0) public_suffix (5.0.1) @@ -192,7 +194,8 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.5.4-x86_64-linux) + sqlite3 (1.5.4) + mini_portile2 (~> 2.8.0) stimulus-rails (1.2.1) railties (>= 6.0.0) thor (1.2.1) @@ -203,6 +206,8 @@ GEM railties (>= 6.0.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) + tzinfo-data (1.2023.3) + tzinfo (>= 1.0.0) warden (1.2.9) rack (>= 2.0.9) web-console (4.2.0) @@ -246,7 +251,7 @@ DEPENDENCIES webdrivers RUBY VERSION - ruby 3.0.5p211 + ruby 3.2.2p53 BUNDLED WITH - 2.4.4 + 2.4.10