Skip to content

Commit 4623141

Browse files
authored
Modified to fit the future blog post (#29)
We will use GitLab's container registry to store the image
1 parent 0419046 commit 4623141

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

gitlab/new-scan-engine/.gitlab-ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
variables:
2-
SYSDIG_SECURE_ENDPOINT: "https://us2.app.sysdig.com"
3-
CI_REGISTRY_HOST: "docker.io"
4-
CI_REGISTRY_NAME: "my-registry"
5-
CI_IMAGE_NAME: "my-image"
2+
SYSDIG_SECURE_ENDPOINT: "https://eu1.app.sysdig.com"
63
CI_IMAGE_TAG: "my-tag"
74

85
stages:
@@ -16,7 +13,7 @@ image:build:
1613
name: gcr.io/kaniko-project/executor:debug
1714
entrypoint: [""]
1815
script:
19-
- /kaniko/executor --dockerfile Dockerfile --destination $CI_REGISTRY_HOST/$CI_REGISTRY_NAME/$CI_IMAGE_NAME:$CI_IMAGE_TAG --no-push --oci-layout-path $(pwd)/build/ --tarPath $(pwd)/build/$CI_IMAGE_TAG.tar
16+
- /kaniko/executor --dockerfile Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_IMAGE_TAG --no-push --oci-layout-path $(pwd)/build/ --tarPath $(pwd)/build/$CI_IMAGE_TAG.tar
2017
artifacts:
2118
paths:
2219
- build/
@@ -46,8 +43,7 @@ image:push:
4643
name: gcr.io/go-containerregistry/crane:debug
4744
entrypoint: [""]
4845
script:
49-
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY_HOST
50-
- crane push build/$CI_IMAGE_TAG.tar $CI_REGISTRY_HOST/$CI_REGISTRY_NAME/$CI_IMAGE_NAME:$CI_IMAGE_TAG
46+
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
47+
- crane push build/$CI_IMAGE_TAG.tar $CI_REGISTRY_IMAGE:$CI_IMAGE_TAG
5148
needs:
5249
- image:scan
53-

gitlab/new-scan-engine/README.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
11
# GitLab CI Demo
22

3-
In this demo we will use GitLab pipelines. We will need to split this pipeline into three different jobs
3+
In this demo we will use GitLab CI/CD pipelines. We will need to split this pipeline into three different jobs:
4+
45
1. Kaniko: Tool used to build docker image
56
2. Sysdig-cli-scanner: Scan docker images for vulnerabilities using the new scan engine developed by Sysding in 2022
67
3. Crane: Push container image to a remote registry
78

8-
## Setup
9-
In GitLab repo settings add variables
10-
`CI_REGISTRY_USER`: Docker username
11-
`CI_REGISTRY_PASSWORD`: Docker user password
12-
`SYSDIG_SECURE_TOKEN`: Sysdig Token
9+
The pipeline leverages the GitLab's container registry to store the container image once the scan has been successfully completed. There are a few special CI/CD variables to use the Container registry (`CI_REGISTRY*`) that are populated automatically by GitLab so there is no need to specify them in our pipeline if we want to use it, cool!
10+
11+
The [official documentation](https://docs.gitlab.com/ee/user/packages/container_registry/index.html#authenticate-by-using-gitlab-cicd) explains this in more detail but the following is an example of the variables' content once they are [automatically populated](https://docs.gitlab.com/ee/ci/variables/#list-all-environment-variables):
1312

14-
Modify the gitlab-ci.yml file to build the image
1513
```
16-
CI_REGISTRY_HOST: "docker.io"
17-
CI_REGISTRY_NAME: my-registry
18-
CI_IMAGE_NAME: "my-image"
19-
CI_IMAGE_TAG: "latest"
14+
CI_REGISTRY="registry.example.com"
15+
CI_REGISTRY_IMAGE="registry.example.com/gitlab-org/gitlab-foss"
16+
CI_REGISTRY_USER="gitlab-ci-token"
17+
CI_REGISTRY_PASSWORD="[masked]"
2018
```
2119

22-
The variables are to build the full image url
23-
`$CI_REGISTRY_HOST/$CI_REGISTRY_NAME/$CI_IMAGE_NAME:$CI_IMAGE_TAG`
24-
We would expect
25-
`docker.io/my-registry/my-image:latest`
20+
## Setup
2621

27-
## Understanding the stages
28-
In order to get around using Docker in docker, these additional stages are necessary
22+
In the GitLab repo settings add the `SYSDIG_SECURE_TOKEN` variable to store the Sysdig Token.
2923

30-
There are three pipeline stages
31-
1. Build
32-
2. Scan
33-
3. Push
24+
Modify the `gitlab-ci.yml` file to replace the image tag if needed:
25+
26+
```
27+
CI_IMAGE_TAG: "latest"
28+
```
29+
30+
## Pipeline stages
3431

3532
### Build
36-
The build stage is using Kaniko. We use a method to build the container to an oci format tarball, saved to the current working directory in `build/` directory. It is not pushed to a remote registry.
37-
We then save the `build/` directory as an artifact.
33+
34+
The build stage leverages Kaniko. The container is built as an OCI format tarball file in `$(pwd)/build/$CI_IMAGE_TAG.tar` and not pushed to a remote registry (it will be done only if the scan is successful).
3835

3936
### Scan
40-
The scan stage is using `sysdig-cli-scanner`. This stage uses a the latest Sysdig scanning method documented here [Sysdig Secure - Vulnerabilities](https://docs.sysdig.com/en/docs/sysdig-secure/vulnerabilities/pipeline/)
41-
We then save the `build/` directory as an artifact for the next step as well as the `report/` directory to review the PDF scan results later.
37+
38+
The scan stage leverages `sysdig-cli-scanner`. This stage uses the latest Sysdig scanning method documented here [Sysdig Secure - Vulnerabilities](https://docs.sysdig.com/en/docs/sysdig-secure/vulnerabilities/pipeline/).
4239

4340
### Push
44-
The push stage is using `crane`. It simply authenticates to your docker registry and pushes the conatiner from the Build stage to the remote registry
41+
42+
The push stage uses `crane` to authenticate to the GitLab registry and to push the container image already built from the Build stage to the remote registry.

0 commit comments

Comments
 (0)