Skip to content
Snippets Groups Projects
Commit 83ab2898 authored by John Jarvis's avatar John Jarvis
Browse files

Merge branch 'master' into 11-10-stable

parents bfec819f a6e9175f
No related branches found
No related tags found
No related merge requests found
Showing
with 388 additions and 177 deletions
doc/ci/variables/img/custom_variable_output.png

68.9 KiB

doc/ci/variables/img/new_custom_variable_example.png

43.1 KiB

doc/ci/variables/img/override_value_via_manual_pipeline_output.png

70.7 KiB

doc/ci/variables/img/override_variable_manual_pipeline.png

28.4 KiB

Loading
Loading
@@ -391,6 +391,11 @@ job:
The above example will run `job` for all branches on `gitlab-org/gitlab-ce`,
except `master` and those with names prefixed with `release/`.
 
NOTE: **Note:**
Because `@` is used to denote the beginning of a ref's repository path,
matching a ref name containing the `@` character in a regular expression
requires the use of the hex character code match `\x40`.
If a job does not have an `only` rule, `only: ['branches', 'tags']` is set by
default. If it doesn't have an `except` rule, it is empty.
 
Loading
Loading
@@ -496,7 +501,7 @@ Learn more about [variables expressions](../variables/README.md#variables-expres
 
#### `only:changes`/`except:changes`
 
Using the `changes` keyword with `only` or `except`, makes it possible to define if
Using the `changes` keyword with `only` or `except` makes it possible to define if
a job should be created based on files modified by a git push event.
 
For example:
Loading
Loading
@@ -513,14 +518,38 @@ docker build:
```
 
In the scenario above, when pushing multiple commits to GitLab to an existing
branch, GitLab creates and triggers `docker build` job, provided that one of the
commits contains changes to either:
branch, GitLab creates and triggers the `docker build` job, provided that one of the
commits contains changes to any of the following:
 
- The `Dockerfile` file.
- Any of the files inside `docker/scripts/` directory.
- Any of the files and subdirectories inside the `dockerfiles` directory.
- Any of the files with `rb`, `py`, `sh` extensions inside the `more_scripts` directory.
 
You can also use glob patterns to match multiple files in either the root directory of the repo, or in _any_ directory within the repo. For example:
```yaml
test:
script: npm run test
only:
changes:
- "*.json"
- "**/*.sql"
```
NOTE: **Note:**
In the example above, the expressions are wrapped double quotes because they are glob patterns. GitLab will fail to parse `.gitlab-ci.yml` files with unwrapped glob patterns.
The following example will skip the CI job if a change is detected in any file in the root directory of the repo with a `.md` extension:
```yaml
build:
script: npm run build
except:
changes:
- "*.md"
```
CAUTION: **Warning:**
There are some caveats when using this feature with new branches and tags. See
the section below.
Loading
Loading
Loading
Loading
@@ -943,7 +943,7 @@ import mixin from 'ee_else_ce/path/mixin';
 
 
```html
<ul v-if="renderIfEE">
<ul v-if="ifEE">
<li>One wrapped</li>
<li>element</li>
<li>that is rendered</li>
Loading
Loading
@@ -962,7 +962,7 @@ For regular JS files, the approach is similar.
 
```javascript
import { ifEE } from '~/lib/utils/common_utils'
if (renderIfEE) {
if (ifEE) {
$('.js-import-git-toggle-button').on('click', () => {
const $projectMirror = $('#project_mirror');
 
Loading
Loading
@@ -976,7 +976,7 @@ if (renderIfEE) {
To separate EE-specific styles in SCSS files, if a component you're adding styles for
is limited to only EE, it is better to have a separate SCSS file in appropriate directory
within `app/assets/stylesheets`.
See [backporting changes](#backporting-changes-from-EE-to-CE) for instructions on how to merge changes safely.
See [backporting changes](#backporting-changes-from-ee-to-ce) for instructions on how to merge changes safely.
 
In some cases, this is not entirely possible or creating dedicated SCSS file is an overkill,
e.g. a text style of some component is different for EE. In such cases,
Loading
Loading
Loading
Loading
@@ -26,6 +26,10 @@ It is not yet a requirement to use Jest. You can view the
[epic](https://gitlab.com/groups/gitlab-org/-/epics/873) of issues
we need to solve before being able to use Jest for all our needs.
 
### Debugging Jest tests
Running `yarn jest-debug` will run Jest in debug mode, allowing you to debug/inspect as described in the [Jest docs](https://jestjs.io/docs/en/troubleshooting#tests-are-failing-and-you-don-t-know-why).
### Timeout error
 
The default timeout for Jest is set in
Loading
Loading
Loading
Loading
@@ -699,6 +699,21 @@ renaming `.staging` to `staging`. Then make sure to uncomment the `when` key of
the `production` job to turn it into a manual action instead of deploying
automatically.
 
### Using components of Auto-DevOps
If you only require a subset of the features offered by Auto-DevOps, you can include
individual Auto-DevOps jobs into your own `.gitlab-ci.yml`.
For example, to make use of [Auto Build](#auto-build), you can add the following to
your `.gitlab-ci.yml`:
```yaml
include:
- template: Jobs/Build.gitlab-ci.yml
```
Consult the [Auto DevOps template] for information on available jobs.
### PostgreSQL database support
 
In order to support applications that require a database,
Loading
Loading
---
last_updated: 2018-02-07
last_updated: 2019-03-27
---
 
# Migrating from MySQL to PostgreSQL
 
> **Note:** This guide assumes you have a working GitLab instance with
> MySQL and want to migrate to bundled PostgreSQL database.
This guide documents how to take a working GitLab instance that uses MySQL and
migrate it to a PostgreSQL database.
 
## Omnibus installation
## Requirements
 
### Prerequisites
[pgloader](http://pgloader.io) 3.4.1+ is required.
 
First, we'll need to enable the bundled PostgreSQL database with up-to-date
schema. Next, we'll use [pgloader](http://pgloader.io) to migrate the data
from the old MySQL database to the new PostgreSQL one.
You can install it directly from your distribution, for example in
Debian/Ubuntu:
 
Here's what you'll need to have installed:
1. Search for the version:
 
- pgloader 3.4.1+
- Omnibus GitLab
- MySQL
```bash
apt-cache madison pgloader
```
 
### Enable bundled PostgreSQL database
1. If the version is 3.4.1+, install it with:
```bash
sudo apt-get install pgloader
```
If your distribution's version is too old, use PostgreSQL's repository:
```bash
# Add repository
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Add key
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Install package
sudo apt-get update
sudo apt-get install pgloader
```
For other distributions, follow the instructions in PostrgreSQL's
[download page](https://www.postgresql.org/download/) to add their repository
and then install `pgloader`.
## Omnibus GitLab installations
For [Omnibus GitLab packages](https://about.gitlab.com/install/), you'll first
need to enable the bundled PostgreSQL:
 
1. Stop GitLab:
 
``` bash
```bash
sudo gitlab-ctl stop
```
 
Loading
Loading
@@ -40,39 +67,34 @@ Here's what you'll need to have installed:
and alike. You could just comment all of them out so that we'll just use
the defaults.
 
1. [Reconfigure GitLab] for the changes to take effect:
``` bash
sudo gitlab-ctl reconfigure
```
1. [Reconfigure GitLab](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure)
for the changes to take effect.
1. Start Unicorn and PostgreSQL so that we can prepare the schema:
 
``` bash
```bash
sudo gitlab-ctl start unicorn
sudo gitlab-ctl start postgresql
```
 
1. Run the following commands to prepare the schema:
 
``` bash
```bash
sudo gitlab-rake db:create db:migrate
```
 
1. Stop Unicorn to prevent other database access from interfering with the loading of data:
 
``` bash
```bash
sudo gitlab-ctl stop unicorn
```
 
After these steps, you'll have a fresh PostgreSQL database with up-to-date schema.
 
### Migrate data from MySQL to PostgreSQL
Now, you can use pgloader to migrate the data from MySQL to PostgreSQL:
Next, we'll use `pgloader` to migrate the data from the old MySQL database to the
new PostgreSQL one:
 
1. Save the following snippet in a `commands.load` file, and edit with your
database `username`, `password` and `host`:
MySQL database `username`, `password` and `host`:
 
```
LOAD DATABASE
Loading
Loading
@@ -90,7 +112,7 @@ Now, you can use pgloader to migrate the data from MySQL to PostgreSQL:
 
1. Start the migration:
 
``` bash
```bash
sudo -u gitlab-psql pgloader commands.load
```
 
Loading
Loading
@@ -117,170 +139,140 @@ Now, you can use pgloader to migrate the data from MySQL to PostgreSQL:
Total import time 1894 1894 0 12.497s
```
 
If there is no output for more than 30 minutes, it's possible pgloader encountered an error. See
the [troubleshooting guide](#Troubleshooting) for more details.
If there is no output for more than 30 minutes, it's possible `pgloader` encountered an error. See
the [troubleshooting guide](#troubleshooting) for more details.
 
1. Start GitLab:
 
``` bash
```bash
sudo gitlab-ctl start
```
 
Now, you can verify that everything worked by visiting GitLab.
### Troubleshooting
#### Permissions
Note that the PostgreSQL user that you use for the above MUST have **superuser** privileges. Otherwise, you may see
a similar message to the following:
```
debugger invoked on a CL-POSTGRES-ERROR:INSUFFICIENT-PRIVILEGE in thread
#<THREAD "lparallel" RUNNING {10078A3513}>:
Database error 42501: permission denied: "RI_ConstraintTrigger_a_20937" is a system trigger
QUERY: ALTER TABLE ci_builds DISABLE TRIGGER ALL;
2017-08-23T00:36:56.782000Z ERROR Database error 42501: permission denied: "RI_ConstraintTrigger_c_20864" is a system trigger
QUERY: ALTER TABLE approver_groups DISABLE TRIGGER ALL;
```
#### Experiencing 500 errors after the migration
If you experience 500 errors after the migration, try to clear the cache:
``` bash
sudo gitlab-rake cache:clear
```
[reconfigure GitLab]: ../administration/restart_gitlab.md#omnibus-gitlab-reconfigure
## Source installation
You can now verify that everything works as expected by visiting GitLab.
 
### Prerequisites
## Source installations
 
#### Install PostgreSQL and create database
For installations from source that use MySQL, you'll first need to
[install PostgreSQL and create a database](../install/installation.md#6-database).
 
See [installation guide](../install/installation.md#6-database).
#### Install [pgloader](http://pgloader.io) 3.4.1+
Install directly from your distro:
``` bash
sudo apt-get install pgloader
```
If this version is too old, use PostgreSQL's repository:
``` bash
# add repository
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# add key
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# install package
sudo apt-get update
sudo apt-get install pgloader
```
### Enable bundled PostgreSQL database
After the database is created, go on with the following steps:
 
1. Stop GitLab:
 
``` bash
sudo service gitlab stop
```
```bash
sudo service gitlab stop
```
 
1. Switch database from MySQL to PostgreSQL
 
``` bash
cd /home/git/gitlab
sudo -u git mv config/database.yml config/database.yml.bak
sudo -u git cp config/database.yml.postgresql config/database.yml
sudo -u git -H chmod o-rwx config/database.yml
```
```bash
cd /home/git/gitlab
sudo -u git mv config/database.yml config/database.yml.bak
sudo -u git cp config/database.yml.postgresql config/database.yml
sudo -u git -H chmod o-rwx config/database.yml
```
1. Install Gems related to Postgresql
 
``` bash
sudo -u git -H rm .bundle/config
sudo -u git -H bundle install --deployment --without development test mysql aws kerberos
```
```bash
sudo -u git -H rm .bundle/config
sudo -u git -H bundle install --deployment --without development test mysql aws kerberos
```
 
1. Run the following commands to prepare the schema:
 
``` bash
sudo -u git -H bundle exec rake db:create db:migrate RAILS_ENV=production
```
```bash
sudo -u git -H bundle exec rake db:create db:migrate RAILS_ENV=production
```
 
After these steps, you'll have a fresh PostgreSQL database with up-to-date schema.
 
### Migrate data from MySQL to PostgreSQL
Now, you can use pgloader to migrate the data from MySQL to PostgreSQL:
Next, we'll use `pgloader` to migrate the data from the old MySQL database to the
new PostgreSQL one:
 
1. Save the following snippet in a `commands.load` file, and edit with your
MySQL `username`, `password` and `host`:
 
```
LOAD DATABASE
FROM mysql://username:password@host/gitlabhq_production
INTO postgresql://postgres@unix://var/run/postgresql:/gitlabhq_production
```
LOAD DATABASE
FROM mysql://username:password@host/gitlabhq_production
INTO postgresql://postgres@unix://var/run/postgresql:/gitlabhq_production
 
WITH include no drop, truncate, disable triggers, create no tables,
create no indexes, preserve index names, no foreign keys,
data only
WITH include no drop, truncate, disable triggers, create no tables,
create no indexes, preserve index names, no foreign keys,
data only
 
ALTER SCHEMA 'gitlabhq_production' RENAME TO 'public'
ALTER SCHEMA 'gitlabhq_production' RENAME TO 'public'
 
;
```
;
```
 
1. Start the migration:
 
``` bash
sudo -u postgres pgloader commands.load
```
```bash
sudo -u postgres pgloader commands.load
```
 
1. Once the migration finishes, you should see a summary table that looks like
the following:
 
```
table name read imported errors total time
----------------------------------------------- --------- --------- --------- --------------
fetch meta data 119 119 0 0.388s
Truncate 119 119 0 1.134s
----------------------------------------------- --------- --------- --------- --------------
public.abuse_reports 0 0 0 0.490s
public.appearances 0 0 0 0.488s
.
.
.
public.web_hook_logs 0 0 0 1.080s
----------------------------------------------- --------- --------- --------- --------------
COPY Threads Completion 4 4 0 2.008s
Reset Sequences 113 113 0 0.304s
Install Comments 0 0 0 0.000s
----------------------------------------------- --------- --------- --------- --------------
Total import time 1894 1894 0 12.497s
```
If there is no output for more than 30 minutes, it's possible pgloader encountered an error. See
the [troubleshooting guide](#Troubleshooting) for more details.
```
table name read imported errors total time
----------------------------------------------- --------- --------- --------- --------------
fetch meta data 119 119 0 0.388s
Truncate 119 119 0 1.134s
----------------------------------------------- --------- --------- --------- --------------
public.abuse_reports 0 0 0 0.490s
public.appearances 0 0 0 0.488s
.
.
.
public.web_hook_logs 0 0 0 1.080s
----------------------------------------------- --------- --------- --------- --------------
COPY Threads Completion 4 4 0 2.008s
Reset Sequences 113 113 0 0.304s
Install Comments 0 0 0 0.000s
----------------------------------------------- --------- --------- --------- --------------
Total import time 1894 1894 0 12.497s
```
If there is no output for more than 30 minutes, it's possible `pgloader` encountered an error. See
the [troubleshooting guide](#troubleshooting) for more details.
 
1. Start GitLab:
 
``` bash
sudo service gitlab start
```
```bash
sudo service gitlab start
```
You can now verify that everything works as expected by visiting GitLab.
## Troubleshooting
Sometimes, you might encounter some errors during or after the migration.
 
Now, you can verify that everything worked by visiting GitLab.
### Database error permission denied
 
### Troubleshooting
The PostgreSQL user that you use for the migration MUST have **superuser** privileges.
Otherwise, you may see a similar message to the following:
 
#### Experiencing 500 errors after the migration
```
debugger invoked on a CL-POSTGRES-ERROR:INSUFFICIENT-PRIVILEGE in thread
#<THREAD "lparallel" RUNNING {10078A3513}>:
Database error 42501: permission denied: "RI_ConstraintTrigger_a_20937" is a system trigger
QUERY: ALTER TABLE ci_builds DISABLE TRIGGER ALL;
2017-08-23T00:36:56.782000Z ERROR Database error 42501: permission denied: "RI_ConstraintTrigger_c_20864" is a system trigger
QUERY: ALTER TABLE approver_groups DISABLE TRIGGER ALL;
```
### Experiencing 500 errors after the migration
 
If you experience 500 errors after the migration, try to clear the cache:
 
``` bash
```bash
# Omnibus GitLab
sudo gitlab-rake cache:clear
# Installations from source
sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production
```
Loading
Loading
@@ -161,8 +161,8 @@ a new set of recovery codes with SSH.
 
1. Run `ssh git@gitlab.example.com 2fa_recovery_codes`.
1. You are prompted to confirm that you want to generate new codes. Continuing this process invalidates previously saved codes.
```
bash
```sh
$ ssh git@gitlab.example.com 2fa_recovery_codes
Are you sure you want to generate new two-factor recovery codes?
Any existing recovery codes you saved will be invalidated. (yes/no)
Loading
Loading
@@ -207,17 +207,17 @@ Sign in and re-enable two-factor authentication as soon as possible.
- You need to take special care to that 2FA keeps working after
[restoring a GitLab backup](../../../raketasks/backup_restore.md).
- To ensure 2FA authorizes correctly with TOTP server, you may want to ensure
your GitLab server's time is synchronized via a service like NTP. Otherwise,
your GitLab server's time is synchronized via a service like NTP. Otherwise,
you may have cases where authorization always fails because of time differences.
- The GitLab U2F implementation does _not_ work when the GitLab instance is accessed from
multiple hostnames, or FQDNs. Each U2F registration is linked to the _current hostname_ at
the time of registration, and cannot be used for other hostnames/FQDNs.
 
For example, if a user is trying to access a GitLab instance from `first.host.xyz` and `second.host.xyz`:
For example, if a user is trying to access a GitLab instance from `first.host.xyz` and `second.host.xyz`:
 
- The user logs in via `first.host.xyz` and registers their U2F key.
- The user logs out and attempts to log in via `first.host.xyz` - U2F authentication succeeds.
- The user logs out and attempts to log in via `second.host.xyz` - U2F authentication fails, because
- The user logs in via `first.host.xyz` and registers their U2F key.
- The user logs out and attempts to log in via `first.host.xyz` - U2F authentication succeeds.
- The user logs out and attempts to log in via `second.host.xyz` - U2F authentication fails, because
the U2F key has only been registered on `first.host.xyz`.
 
[Google Authenticator]: https://support.google.com/accounts/answer/1066447?hl=en
Loading
Loading
Loading
Loading
@@ -314,12 +314,6 @@ install it manually.
 
## Installing applications
 
NOTE: **Note:**
Before starting the installation of applications, make sure that time is synchronized
between your GitLab server and your Kubernetes cluster. Otherwise, installation could fail
and you may get errors like `Error: remote error: tls: bad certificate`
in the `stdout` of pods created by GitLab in your Kubernetes cluster.
GitLab provides a one-click install for various applications which can
be added directly to your configured cluster. Those applications are
needed for [Review Apps](../../../ci/review_apps/index.md) and
Loading
Loading
@@ -378,6 +372,29 @@ Upgrades will reset values back to the values built into the `runner`
chart plus the values set by
[`values.yaml`](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/vendor/runner/values.yaml)
 
### Troubleshooting applications
Applications can fail with the following error:
```text
Error: remote error: tls: bad certificate
```
To avoid installation errors:
- Before starting the installation of applications, make sure that time is synchronized
between your GitLab server and your Kubernetes cluster.
- Ensure certificates are not out of sync. When installing applications, GitLab expects a new cluster with no previous installation of Tiller.
You can confirm that the certificates match via `kubectl`:
```sh
kubectl get configmaps/values-content-configuration-ingress -n gitlab-managed-apps -o \
"jsonpath={.data['cert\.pem']}" | base64 -d > a.pem
kubectl get secrets/tiller-secret -n gitlab-managed-apps -o "jsonpath={.data['ca\.crt']}" | base64 -d > b.pem
diff a.pem b.pem
```
## Getting the external endpoint
 
NOTE: **Note:**
Loading
Loading
Loading
Loading
@@ -214,7 +214,7 @@ The sample function can now be triggered from any HTTP client using a simple `PO
--header "Content-Type: application/json" \
--request POST \
--data '{"GitLab":"FaaS"}' \
<http://functions-echo.functions-1.functions.example.com/>
http://functions-echo.functions-1.functions.example.com
```
2. Using a web-based tool (ie. postman, restlet, etc)
 
Loading
Loading
Loading
Loading
@@ -31,7 +31,7 @@ discussions, and descriptions:
| `/reassign @user1 @user2` | Change assignee | ✓ | ✓ |
| `/milestone %milestone` | Set milestone | ✓ | ✓ |
| `/remove_milestone` | Remove milestone | ✓ | ✓ |
| `/label ~label1 ~label2` | Add label(s) | ✓ | ✓ |
| `/label ~label1 ~label2` | Add label(s). Label names can also start without ~ but mixed syntax is not supported. | ✓ | ✓ |
| `/unlabel ~label1 ~label2` | Remove all or specific label(s)| ✓ | ✓ |
| `/relabel ~label1 ~label2` | Replace label | ✓ | ✓ |
| <code>/copy_metadata #issue &#124; !merge_request</code> | Copy labels and milestone from other issue or merge request | ✓ | ✓ |
Loading
Loading
Loading
Loading
@@ -690,6 +690,10 @@ module API
# Deprecated
expose :allow_collaboration, as: :allow_maintainer_to_push, if: -> (merge_request, _) { merge_request.for_fork? }
 
expose :reference do |merge_request, options|
merge_request.to_reference(options[:project])
end
expose :web_url do |merge_request|
Gitlab::UrlBuilder.build(merge_request)
end
Loading
Loading
@@ -726,6 +730,8 @@ module API
merge_request.metrics&.pipeline
end
 
expose :head_pipeline, using: 'API::Entities::Pipeline'
expose :diff_refs, using: Entities::DiffRefs
 
# Allow the status of a rebase to be determined
Loading
Loading
@@ -1267,6 +1273,9 @@ module API
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
expose :duration
expose :coverage
expose :detailed_status, using: DetailedStatusEntity do |pipeline, options|
pipeline.detailed_status(options[:current_user])
end
end
 
class PipelineSchedule < Grape::Entity
Loading
Loading
@@ -1389,8 +1398,13 @@ module API
expose :name, :script, :timeout, :when, :allow_failure
end
 
class Port < Grape::Entity
expose :number, :protocol, :name
end
class Image < Grape::Entity
expose :name, :entrypoint
expose :ports, using: JobRequest::Port
end
 
class Service < Image
Loading
Loading
Loading
Loading
@@ -310,7 +310,7 @@ module API
.flatten
 
present paginate(::Kaminari.paginate_array(merge_requests)),
with: Entities::MergeRequestBasic,
with: Entities::MergeRequest,
current_user: current_user,
project: user_project
end
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ module Gitlab
module Ci
module Build
class Image
attr_reader :alias, :command, :entrypoint, :name
attr_reader :alias, :command, :entrypoint, :name, :ports
 
class << self
def from_image(job)
Loading
Loading
@@ -26,17 +26,25 @@ module Gitlab
def initialize(image)
if image.is_a?(String)
@name = image
@ports = []
elsif image.is_a?(Hash)
@alias = image[:alias]
@command = image[:command]
@entrypoint = image[:entrypoint]
@name = image[:name]
@ports = build_ports(image).select(&:valid?)
end
end
 
def valid?
@name.present?
end
private
def build_ports(image)
image[:ports].to_a.map { |port| ::Gitlab::Ci::Build::Port.new(port) }
end
end
end
end
Loading
Loading
# frozen_string_literal: true
module Gitlab
module Ci
module Build
class Port
DEFAULT_PORT_NAME = 'default_port'.freeze
DEFAULT_PORT_PROTOCOL = 'http'.freeze
attr_reader :number, :protocol, :name
def initialize(port)
@name = DEFAULT_PORT_NAME
@protocol = DEFAULT_PORT_PROTOCOL
case port
when Integer
@number = port
when Hash
@number = port[:number]
@protocol = port.fetch(:protocol, @protocol)
@name = port.fetch(:name, @name)
end
end
def valid?
@number.present?
end
end
end
end
end
Loading
Loading
@@ -9,24 +9,24 @@ module Gitlab
#
class Image < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
 
ALLOWED_KEYS = %i[name entrypoint].freeze
ALLOWED_KEYS = %i[name entrypoint ports].freeze
 
validations do
validates :config, hash_or_string: true
validates :config, allowed_keys: ALLOWED_KEYS
validates :config, disallowed_keys: %i[ports], unless: :with_image_ports?
 
validates :name, type: String, presence: true
validates :entrypoint, array_of_strings: true, allow_nil: true
end
 
def hash?
@config.is_a?(Hash)
end
entry :ports, Entry::Ports,
description: 'Ports used expose the image'
 
def string?
@config.is_a?(String)
end
attributes :ports
 
def name
value[:name]
Loading
Loading
@@ -42,6 +42,14 @@ module Gitlab
 
{}
end
def with_image_ports?
opt(:with_image_ports)
end
def skip_config_hash_validation?
true
end
end
end
end
Loading
Loading
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module Entry
##
# Entry that represents a configuration of an Image Port.
#
class Port < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
ALLOWED_KEYS = %i[number protocol name].freeze
validations do
validates :config, hash_or_integer: true
validates :config, allowed_keys: ALLOWED_KEYS
validates :number, type: Integer, presence: true
validates :protocol, type: String, inclusion: { in: %w[http https], message: 'should be http or https' }, allow_blank: true
validates :name, type: String, presence: false, allow_nil: true
end
def number
value[:number]
end
def protocol
value[:protocol]
end
def name
value[:name]
end
def value
return { number: @config } if integer?
return @config if hash?
{}
end
end
end
end
end
end
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module Entry
##
# Entry that represents a configuration of the ports of a Docker service.
#
class Ports < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
validations do
validates :config, type: Array
validates :config, port_name_present_and_unique: true
validates :config, port_unique: true
end
def compose!(deps = nil)
super do
@entries = []
@config.each do |config|
@entries << ::Gitlab::Config::Entry::Factory.new(Entry::Port)
.value(config || {})
.with(key: "port", parent: self, description: "port definition.") # rubocop:disable CodeReuse/ActiveRecord
.create!
end
@entries.each do |entry|
entry.compose!(deps)
end
end
end
def value
@entries.map(&:value)
end
def descendants
@entries
end
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment