Skip to content

Instantly share code, notes, and snippets.

@luk4s
Last active April 10, 2022 08:05
Show Gist options
  • Save luk4s/64ff1c3a0c4fb35ae39f2aa16b9155df to your computer and use it in GitHub Desktop.
Save luk4s/64ff1c3a0c4fb35ae39f2aa16b9155df to your computer and use it in GitHub Desktop.
regular Rails appplication pipeline with docker build
---
stages:
- ".pre"
- build
- test
- release
- ".post"
variables:
RUBY_VERSION: 2.7.2
POSTGRES_DB: "$CI_PROJECT_NAME"
DATABASE_NAME: "$CI_PROJECT_NAME"
POSTGRES_USER: postgres
DATABASE_HOST: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --data-checksums"
POSTGRES_HOST_AUTH_METHOD: trust
.job_template:
image: ruby:$RUBY_VERSION
tags:
- docker
services:
- postgres:12
before_script:
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
- curl -sL https://deb.nodesource.com/setup_14.x | bash -
- apt-get update && apt-get install -y nodejs yarn firefox-esr
- curl -sL "https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz"
| tar -xz -C /usr/local/bin
- yarn install
- bundle config set deployment 'true'
- bundle install
- bundle exec rails db:setup
cache:
key: "$CI_PROJECT_NAME-$RUBY_VERSION"
paths:
- vendor/bundle
- vendor/ruby
- ".bundle"
- node_modules
build assets:
extends: ".job_template"
stage: build
script:
- bundle exec rails assets:precompile
artifacts:
paths:
- public/assets
- public/packs
expire_in: 1 day
rspec:
extends: .job_template
stage: test
script:
- bundle exec rspec
jest:
extends: .job_template
stage: test
script:
- yarn test
package assets:
stage: release
only:
- master
image: curlimages/curl:latest
variables:
PACKAGE_NAME: assets.tar.gz
script:
- tar -czf ./$PACKAGE_NAME public/{assets,packs}
- curl --header "JOB-TOKEN:$CI_JOB_TOKEN" --upload-file ./$PACKAGE_NAME ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$CI_PROJECT_NAME_assets/1.0.0/$PACKAGE_NAME
build image:
stage: release
only:
- master
variables:
IMAGE_TAG: "$CI_REGISTRY_IMAGE"
script:
- export RELEASE_IMAGE_TAG=$IMAGE_TAG:$(date +%F)
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $RELEASE_IMAGE_TAG .
- docker push $RELEASE_IMAGE_TAG
- docker tag $RELEASE_IMAGE_TAG $IMAGE_TAG:latest
- docker push $IMAGE_TAG:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment