Skip to content

Instantly share code, notes, and snippets.

@Ex-Ark
Created April 2, 2020 08:23
Show Gist options
  • Save Ex-Ark/70188687d109d6aa42e74f47d17c06a9 to your computer and use it in GitHub Desktop.
Save Ex-Ark/70188687d109d6aa42e74f47d17c06a9 to your computer and use it in GitHub Desktop.
Gitlab CI config for testing, building static swagger documentation and deploying doc
stages:
- test
- documentation
- deploy
rspec:
stage: test
# Cache gems in between builds
cache:
paths:
- vendor/bundle
image: "ruby:2.5.7"
services:
- mysql:5.7
variables:
MYSQL_DATABASE: my_db
MYSQL_ROOT_PASSWORD: for_test_only
BUNDLE_PATH: vendor/bundle
before_script:
- apt-get update -qq && apt-get install -y -qq mariadb-server mariadb-client libmariadbclient-dev
- gem install bundler
- RAILS_ENV=test bundle check || bundle install --jobs $(nproc)
- cp config/database.yml.gitlab config/database.yml
- cp config/secrets.yml.example config/secrets.yml
- RAILS_ENV=test bundle exec rake db:create db:schema:load
script:
- RAILS_ENV=test bundle exec rspec
- RAILS_ENV=test bundle exec rake doc
artifacts:
paths:
- swagger/swagger.json
generate_doc:
stage: documentation
image:
name: "swaggerapi/swagger-codegen-cli:2.4.10"
entrypoint: [""]
script:
- /usr/bin/java -jar /opt/swagger-codegen-cli/swagger-codegen-cli.jar generate -i ./swagger/swagger.json -l html2
artifacts:
paths:
- index.html
deploy_doc:
image: "alpine"
stage: deploy
before_script:
- apk add openssh-client sshpass
- export SSHPASS="$SSH_USER_PASS"
script:
- sshpass -e scp -q -o stricthostkeychecking=no index.html $SSH_USER@$SSH_HOST:www/
@Ex-Ark
Copy link
Author

Ex-Ark commented Apr 2, 2020

  • swagger gem produces swagger.json on stage rspec directly from specs
  • swagger cli convert the given .json in a single static html documentation
  • the deploy_doc stage pushes the html file to a www/ public html directory, in order to make it available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment