Adds integration test in Earthfile

parent 1edbd972
Pipeline #197667921 failed with stage
in 23 minutes and 43 seconds
docker-build-master:
# Official docker image.
image: docker:git
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.3.6/earth-linux-amd64 -O /usr/local/bin/earth && chmod +x /usr/local/bin/earth'
script:
- earth +prod
- earth -P +integration-test
- docker push "$CI_REGISTRY_IMAGE"
only:
- master
docker-build:
# Official docker image.
image: docker:git
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.3.6/earth-linux-amd64 -O /usr/local/bin/earth && chmod +x /usr/local/bin/earth'
script:
- earth +prod
- earth -P +integration-test
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
except:
- master
......@@ -31,7 +31,18 @@ gems:
assets:
FROM +gems
ENV RAILS_ENV production
COPY . /application
COPY app/assets /application/app/assets
COPY app/models /application/app/models
COPY app/sweepers /application/app/sweepers
COPY config/environments/production.rb /application/config/environments/production.rb
COPY config/initializers /application/config/initializers
COPY config/application.rb /application/config/application.rb
COPY config/boot.rb /application/config/boot.rb
COPY config/database.yml /application/config/database.yml
COPY config/environment.rb /application/config/environment.rb
COPY config/redis.yml /application/config/redis.yml
COPY vendor /application/vendor
COPY Rakefile /application
RUN bundle exec rake assets:precompile RAILS_ENV=production
SAVE ARTIFACT public/assets assets
......@@ -42,7 +53,18 @@ prod:
FROM +gems
ENV RAILS_ENV production
RUN useradd -ms /bin/bash brewformulas
COPY . /application
COPY app /application/app
COPY bin /application/bin
COPY config /application/config
COPY db /application/db
COPY lib /application/lib
COPY public /application/public
COPY vendor /application/vendor
COPY config.ru /application
COPY Gemfile* /application
COPY package.json /application
COPY Rakefile /application
COPY VERSION /application
COPY +assets/assets public/assets
RUN chown -R brewformulas:users /application
EXPOSE 3000
......@@ -50,18 +72,48 @@ prod:
CMD ["bin/rails server -b 0.0.0.0"]
SAVE IMAGE registry.gitlab.com/zedtux/brewformulas.org:latest
# `ci` is based on the production image, in order to keep an environmnet as
# `ci` is based on the production image, in order to keep an environment as
# close as possible with production when running the tests.
# Nonetheless it install additionnal gems used to run the tests.
ci:
FROM +prod
ENV RAILS_ENV test
COPY features /application/features
COPY script /application/script
COPY spec /application/spec
COPY .coveralls.yml /application/.coveralls.yml
RUN bundle config --delete without
RUN bundle install --gemfile=/application/Gemfile \
--jobs=8 \
--path=/bundle \
--without development
SAVE IMAGE registry.gitlab.com/zedtux/brewformulas.org:latest-ci
CMD ["rake"]
SAVE IMAGE
integration-test:
FROM docker:19.03.13-dind
RUN apk --update --no-cache add docker-compose jq
COPY docker-compose.yml ./
WITH DOCKER
DOCKER PULL postgres:9.6.2
DOCKER PULL redis:3.2.8
DOCKER PULL memcached:1.5.3-alpine
DOCKER LOAD +ci zedtux/brewformulas.org:dev
RUN docker-compose up -d \
&& POSTGRESQL_CONTAINER_IPADDR=$(docker inspect default_postgres_1 \
| jq -r '.[0].NetworkSettings.Networks.default_default.IPAddress') \
&& for i in {1..30}; do nc -z $POSTGRESQL_CONTAINER_IPADDR 5432 && break; sleep 1; done; \
docker run --network=host \
--env DATABASE_HOST=$POSTGRESQL_CONTAINER_IPADDR \
--env POSTGRESQL_USER=postgres \
--env RAILS_ENV=test \
zedtux/brewformulas.org:dev bash -c 'bundle exec rake db:setup \
&& bundle exec rake' \
&& docker-compose down
END
# `dev` is based on the production image, in order to keep an environmnet as
# close as possible with produciton and then installs all the other gems for
......@@ -76,4 +128,4 @@ dev:
--path=/bundle
# Allow adding/removing/updating gems
RUN chown -R brewformulas:users /bundle
SAVE IMAGE registry.gitlab.com/zedtux/brewformulas.org:latest-dev
SAVE IMAGE registry.gitlab.com/zedtux/brewformulas.org:dev
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative 'config/application'
begin
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
RSpec::Core::RakeTask.new
task default: [:spec, :cucumber]
task default: %i[spec cucumber]
rescue LoadError => error
unless Rails.env.production?
puts 'WARNING: Could not load the RSpec and/or Cucumber Rake tasks' \
......
......@@ -20,7 +20,7 @@ default: &default
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: database
host: <%= ENV["DATABASE_HOST"] || 'postgres' %>
username: postgres
port: 5432
......@@ -60,7 +60,6 @@ development:
# Do not set this db to the same as development or production.
test: &test
<<: *default
host: <%= ENV["DATABASE_HOST"] || 'postgres' %>
database: brewformulas_org_test
# As with config/secrets.yml, you never want to store sensitive information,
......
......@@ -9,27 +9,28 @@ services:
image: memcached:1.5.3-alpine
bundle:
image: zedtux/brewformulas.org:latest-dev
image: zedtux/brewformulas.org:dev
command: echo Bundler data container
volumes:
- /bundle
workers:
image: zedtux/brewformulas.org:latest-dev
image: zedtux/brewformulas.org:dev
command: bundle exec sidekiq
links:
- postgres:database
- redis:redis
- memcached
environment:
- DATABASE_HOST=database
- MEMCACHE_SERVERS=memcached
- POSTGRESQL_USER=postgres
- RAILS_ENV=development
- MEMCACHE_SERVERS=memcached
volumes:
- .:/application/
volumes_from:
- bundle
web:
image: zedtux/brewformulas.org:latest-dev
image: zedtux/brewformulas.org:dev
build: .
command: bin/rails server -b 0.0.0.0 -p 3000
links:
......@@ -39,10 +40,11 @@ services:
ports:
- "3000:3000"
environment:
- DATABASE_HOST=database
- MEMCACHE_SERVERS=memcached
- POSTGRESQL_USER=postgres
- RAILS_ENV=development
- VIRTUAL_HOST=localhost:3000
- MEMCACHE_SERVERS=memcached
volumes:
- .:/application/
volumes_from:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment