Commit d4b25520 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: migrate to CI/CD component

⚠️ requires GitLab 16.6 or later
parent 75e35080
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ include:
    file: '/templates/validation.yml'
  - project: 'to-be-continuous/bash'
    ref: '3.3'
    file: 'templates/gitlab-ci-bash.yml'
    file: '/templates/gitlab-ci-bash.yml'
  - project: 'to-be-continuous/semantic-release'
    ref: '3.7'
    file: '/templates/gitlab-ci-semrel.yml'    
+46 −22
Original line number Diff line number Diff line
@@ -5,13 +5,36 @@ your source code with [Source-to-Image](https://github.com/openshift/source-to-i

## Usage

In order to include this template in your project, add the following to your `gitlab-ci.yml`:
This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component-in-a-cicd-configuration) 
or using the legacy [`include:project`](https://docs.gitlab.com/ee/ci/yaml/index.html#includeproject) syntax.

### Use as a CI/CD component

Add the following to your `gitlab-ci.yml`:

```yaml
include:
  # 1: include the component
  - component: gitlab.com/to-be-continuous/s2i/gitlab-ci-s2i@1.0.1
    # 2: set/override component inputs
    inputs:
      builder-image: "fabric8/s2i-java:latest-java11" # ⚠ this is only an example
```

### Use as a CI/CD template (legacy)

Add the following to your `gitlab-ci.yml`:

```yaml
include:
  # 1: include the template
  - project: 'to-be-continuous/s2i'
    ref: '1.0.1'
    file: '/templates/gitlab-ci-s2i.yml'

variables:
  # 2: set/override template variables
  S2I_BUILDER_IMAGE: "fabric8/s2i-java:latest-java11" # ⚠ this is only an example
```

## Understanding the S2I template
@@ -20,11 +43,12 @@ include:

The S2I template uses some global configuration used throughout all jobs.

| Name               | Description                                | Default value     |
| Input / Variable | Description                                | Default value     |
| ------------------ | ------------------------------------------ | ----------------- |
| `S2I_SKOPEO_IMAGE` | The container image used to run [skopeo](https://github.com/containers/skopeo) | `quay.io/skopeo/stable:latest` |
| `S2I_VERSION`      | The target S2I version to install/use      | `latest`|
| `S2I_PLATFORM`     | The target S2I platform to install/use     | `linux-386` |
| `dind-image` / `S2I_DIND_IMAGE` | The Docker image used to run the Docker daemon | `registry.hub.docker.com/library/docker:dind`    |
| `skopeo-image` / `S2I_SKOPEO_IMAGE` | The container image used to run [skopeo](https://github.com/containers/skopeo) | `quay.io/skopeo/stable:latest` |
| `version` / `S2I_VERSION` | The target S2I version to install/use      | `latest`|
| `platform` / `S2I_PLATFORM` | The target S2I platform to install/use     | `linux-386` |

### Images

@@ -46,10 +70,10 @@ In practice:

The **snapshot** and **release** images are defined by the following variables:

| Name                   | Description        | Default value                                     |
| Input / Variable | Description        | Default value                                     |
| ---------------------- | ------------------ | ------------------------------------------------- |
| `S2I_SNAPSHOT_IMAGE`   | S2I snapshot image | `$CI_REGISTRY_IMAGE/snapshot:$CI_COMMIT_REF_SLUG` |
| `S2I_RELEASE_IMAGE`    | S2I release image  | `$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME`          |
| `snapshot-image` / `S2I_SNAPSHOT_IMAGE` | S2I snapshot image | `$CI_REGISTRY_IMAGE/snapshot:$CI_COMMIT_REF_SLUG` |
| `release-image` / `S2I_RELEASE_IMAGE` | S2I release image  | `$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME`          |

As you can see, the S2I template is configured by default to use the GitLab container registry.
You may perfectly override this and use another container registry, but be aware of a few things:
@@ -71,7 +95,7 @@ But when using other registry(ies), you'll have also to **configure appropriate
If you use the **same registry** for both snapshot and release images, you shall use the following configuration
variables:

| Name                             | Description                            |
| Input / Variable | Description                            |
| -------------------------------- | -------------------------------------- |
| :lock: `S2I_REGISTRY_USER`    | container registry username for image registry |
| :lock: `S2I_REGISTRY_PASSWORD`| container registry password for image registry  |
@@ -80,7 +104,7 @@ variables:

If you use **different registries** for snapshot and release images, you shall use separate configuration variables:

| Name                                     | Description                            |
| Input / Variable | Description                            |
| ---------------------------------------- | -------------------------------------- |
| :lock: `S2I_REGISTRY_SNAPSHOT_USER`   | container registry username for snapshot image registry |
| :lock: `S2I_REGISTRY_SNAPSHOT_PASSWORD`| container registry password for snapshot image registry |
@@ -111,15 +135,15 @@ It is bound to the `package-build` stage, and uses the following variables:

It uses the following variable:

| Name                | Description                                                                        | Default value |
| Input / Variable | Description                                                                        | Default value |
|---------------------|------------------------------------------------------------------------------------|---------------|
| `S2I_ROOT_DIR`      | Relative path to the application source code base directory in your repository     | `.`           |
| `S2I_BUILDER_IMAGE` | The S2I [builder image](https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md) used to build your application image | _none_ (required) |
| `S2I_BUILD_EXTRA_FLAGS` | S2I build [extra flags](https://github.com/openshift/source-to-image/blob/master/docs/cli.md#s2i-build) | _none_ |
| `root-dir` / `S2I_ROOT_DIR` | Relative path to the application source code base directory in your repository     | `.`           |
| `builder-image` / `S2I_BUILDER_IMAGE` | The S2I [builder image](https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md) used to build your application image | _none_ (required) |
| `build-extra-flags` / `S2I_BUILD_EXTRA_FLAGS` | S2I build [extra flags](https://github.com/openshift/source-to-image/blob/master/docs/cli.md#s2i-build) | _none_ |

This job produces _output variables_ that are propagated to downstream jobs (using [dotenv artifacts](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#artifactsreportsdotenv)):

| Name               | Description                                            | Example                                 |
| Input / Variable | Description                                            | Example                                 |
| ------------------ | ------------------------------------------------------ | --------------------------------------- |
| `s2i_image`        | snapshot image name **with tag**                       | `registry.gitlab.com/acme/website/snapshot:main` |
| `s2i_image_digest` | snapshot image name **with digest** (no tag)           | `registry.gitlab.com/acme/website/snapshot@sha256:b7914a91...` |
@@ -133,17 +157,17 @@ They may be freely used in downstream jobs (for instance to deploy the upstream

This job pushes (_promotes_) the built image as the _release_ image using [skopeo](https://github.com/containers/skopeo).

| Name                  | Description                                                                 | Default value     |
| Input / Variable | Description                                                                 | Default value     |
| --------------------- | --------------------------------------------------------------------------- | ----------------- |
| `S2I_PUBLISH_ARGS`    | Additional [`skopeo copy` arguments](https://github.com/containers/skopeo/blob/master/docs/skopeo-copy.1.md#options) | _(none)_          |
| `S2I_PROD_PUBLISH_STRATEGY`| Defines the publish to production strategy. One of `manual` (i.e. _one-click_), `auto` or `none` (disabled). | `manual` |
| `S2I_RELEASE_EXTRA_TAGS_PATTERN` | Defines the image tag pattern that `$S2I_RELEASE_IMAGE` should match to push extra tags (supports capturing groups - [see below](#using-extra-tags)) | `^v?(?P<major>[0-9]+)\\.(?P<minor>[0-9]+)\\.(?P<patch>[0-9]+)(?P<suffix>(?P<prerelease>-[0-9A-Za-z-\\.]+)?(?P<build>\\+[0-9A-Za-z-\\.]+)?)$` _(SemVer pattern)_ |
| `S2I_RELEASE_EXTRA_TAGS`   | Defines extra tags to publish the _release_ image (supports capturing group references from `$S2I_RELEASE_EXTRA_TAGS_PATTERN` - [see below](#using-extra-tags))       | _(none)_          |
| `S2I_SEMREL_RELEASE_DISABLED` | Set to `true` to disable [semantic-release integration](#semantic-release-integration)   | _none_ (enabled) |
| `publish-args` / `S2I_PUBLISH_ARGS` | Additional [`skopeo copy` arguments](https://github.com/containers/skopeo/blob/master/docs/skopeo-copy.1.md#options) | _(none)_          |
| `prod-publish-strategy` / `S2I_PROD_PUBLISH_STRATEGY` | Defines the publish to production strategy. One of `manual` (i.e. _one-click_), `auto` or `none` (disabled). | `manual` |
| `release-extra-tags-pattern` / `S2I_RELEASE_EXTRA_TAGS_PATTERN` | Defines the image tag pattern that `$S2I_RELEASE_IMAGE` should match to push extra tags (supports capturing groups - [see below](#using-extra-tags)) | `^v?(?P<major>[0-9]+)\\.(?P<minor>[0-9]+)\\.(?P<patch>[0-9]+)(?P<suffix>(?P<prerelease>-[0-9A-Za-z-\\.]+)?(?P<build>\\+[0-9A-Za-z-\\.]+)?)$` _(SemVer pattern)_ |
| `release-extra-tags` / `S2I_RELEASE_EXTRA_TAGS` | Defines extra tags to publish the _release_ image (supports capturing group references from `$S2I_RELEASE_EXTRA_TAGS_PATTERN` - [see below](#using-extra-tags))       | _(none)_          |
| `semrel-release-disabled` / `S2I_SEMREL_RELEASE_DISABLED` | Set to `true` to disable [semantic-release integration](#semantic-release-integration)   | _none_ (enabled) |

This job produces _output variables_ that are propagated to downstream jobs (using [dotenv artifacts](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#artifactsreportsdotenv)):

| Name               | Description                                           | Example                                 |
| Input / Variable | Description                                           | Example                                 |
| ------------------ | ----------------------------------------------------- | --------------------------------------- |
| `s2i_image`        | release image name **with tag**                       | `registry.gitlab.com/acme/website:main` |
| `s2i_image_digest` | release image name **with digest** (no tag)           | `registry.gitlab.com/acme/website@sha256:b7914a91...` |
+2 −2
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@ if [[ "$curVer" ]]; then
  log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..."

  # replace in README
  sed -e "s/ref: '$curVer'/ref: '$nextVer'/" README.md > README.md.next
  sed -e "s/ref: *'$curVer'/ref: '$nextVer'/" -e "s/ref: *\"$curVer\”/ref: \”$nextVer\”/" -e "s/component: *\(.*\)@$curVer/component: \1@$nextVer/" README.md > README.md.next
  mv -f README.md.next README.md

  # replace in template and variants
  for tmpl in templates/*.yml
  do
    sed -e "s/\"$curVer\"/\"$nextVer\"/" "$tmpl" > "$tmpl.next"
    sed -e "s/command: *\[\"--service\", \"\(.*\)\", \"$curVer\"\]/command: [\"--service\", \"\1\", \"$nextVer\"]/" "$tmpl" > "$tmpl.next"
    mv -f "$tmpl.next" "$tmpl"
  done
else
+7 −0
Original line number Diff line number Diff line
@@ -3,7 +3,14 @@
  "description": "Build reproducible container images from your source code with [Source-to-Image](https://github.com/openshift/source-to-image) (S2I)",
  "template_path": "templates/gitlab-ci-s2i.yml",
  "kind": "package",
  "prefix": "s2i",
  "is_component": true,
  "variables": [
    {
      "name": "S2I_DIND_IMAGE",
      "description": "The image used to run the Docker daemon",
      "default": "registry.hub.docker.com/library/docker:dind"
    },
    {
      "name": "S2I_SKOPEO_IMAGE",
      "description": "The image used to push the built container image with Skopeo",
+6.75 KiB (15.1 KiB)
Loading image diff...
Loading