We had three files that were almost identical, and we can use environment variables to specify the differences. Note we're using the `PGUSER` and `PGPASSWORD` variables, since these variables will automatically be used by the PostgreSQL client when we have a blank `username` and `password` keys in the `database.yml` file (which we did until now). The difference between these variables and the `POSTGRES_USER` and `POSTGRES_PASSWORD` variables is that the `PG` variables are used by the client connecting to the database, while the `POSTGRES_` variables are used by the Docker postgresql image when creating the database superuser. For consistency with the code in our github workflows (and everywhere else in the postgres world), we're respecting this double standard. The fact that there are two different names for what's basically the same thing makes the code confusing, though, particularly when running the docker-compose commands, since we get the password from an environment variable but we have to assign two different environment variables with it. So we're accepting both `PGPASSWORD` and `POSTGRES_PASSWORD` variables in the database configuration file. This way, developers using docker-compose can use `POSTGRES_PASSWORD` for everything and it'll work fine. We're also making `PGPASSWORD` default to `POSTGRES_PASSWORD` so we don't get a warning if we only set `POSTGRES_PASSWORD`: ``` WARN[0000] The "PGPASSWORD" variable is not set. Defaulting to a blank string. ``` Also note we're using `DB_HOST` instead of `PGHOST` because that's the variable Rails currently uses by default for new applications [1]. Finally, note we're using `.presence` in the `ENV` calls in the database.yml file. The `PGPASSWORD` variable was set to an empty string when running docker-compose, so using `ENV["PGPASSWORD"] ||` wouldn't work. [1] https://github.com/rails/rails/blob/c90a8701e5/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt#L22
54 lines
1.3 KiB
YAML
54 lines
1.3 KiB
YAML
stages:
|
|
- test
|
|
- lint
|
|
|
|
tests:
|
|
image: "ruby:3.2.5"
|
|
stage: test
|
|
services:
|
|
- postgres:13.16
|
|
cache:
|
|
key: consul
|
|
paths:
|
|
- vendor/
|
|
variables:
|
|
DB_HOST: postgres
|
|
PGUSER: consul
|
|
PGPASSWORD: password
|
|
POSTGRES_USER: consul
|
|
POSTGRES_PASSWORD: password
|
|
RAILS_ENV: test
|
|
TEST_COVERAGE: 1
|
|
parallel: 5
|
|
script:
|
|
- apt-get update && apt-get install -y nodejs npm chromium
|
|
- for i in config/*.example; do cp "$i" "${i/.example}"; done
|
|
- bundle --without development
|
|
- npm clean-install
|
|
- bundle exec rake db:setup
|
|
- bundle exec rake assets:precompile > /dev/null 2>&1
|
|
- bin/knapsack_pro_rspec
|
|
artifacts:
|
|
when: on_failure
|
|
paths:
|
|
- tmp/screenshots/
|
|
|
|
# To make this job work, create a Personal Access Token with permissions
|
|
# to comment on your repository and add a variable named
|
|
# PRONTO_GITLAB_API_PRIVATE_TOKEN to your repository CI/CD settings
|
|
# giving it the value of the Personal Access Token
|
|
linters:
|
|
image: "ruby:3.2.5"
|
|
stage: lint
|
|
cache:
|
|
key: consul
|
|
paths:
|
|
- vendor/
|
|
only:
|
|
- merge_requests
|
|
script:
|
|
- apt-get update && apt-get install -y nodejs cmake pkg-config
|
|
- bundle --without test
|
|
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
|
- bundle exec pronto run -f gitlab_mr -c origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|