Skip to content

Commit e50dc56

Browse files
0snug0Eric Lugoairadier
authored
Gitlab examples (#13)
Add gitlab example to inline scan examples Co-authored-by: Eric Lugo <[email protected]> Co-authored-by: Álvaro Iradier <[email protected]>
1 parent f25a6c9 commit e50dc56

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ In this [repository](https://github.com/sysdiglabs/secure-inline-scan-examples/)
136136
* [Build and scan](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/jenkins/jenkins-build-and-scan)
137137
* [Build, push and scan from repository](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/jenkins/jenkins-build-push-scan-from-repo)
138138
* [Build, push and scan using Openshift internal registry](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/jenkins/jenkins-openshift-internal-registry)
139+
* [Gitlab](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/gitlab)
139140
* [Tekton](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/tekton)
140141
* [Tekton alpha API](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/tekton/alpha)
141142
* [Tekton beta API](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/tekton/beta)

gitlab/.gitlab-ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
variables:
2+
SYSDIG_SECURE_ENDPOINT: "https://secure.sysdig.com"
3+
CI_REGISTRY_HOST: "docker.io"
4+
CI_REGISTRY_NAME: "my-registry"
5+
CI_IMAGE_NAME: "my-image"
6+
CI_IMAGE_TAG: "my-tag"
7+
8+
stages:
9+
- build
10+
- scan
11+
- push
12+
13+
image:build:
14+
stage: build
15+
image:
16+
name: gcr.io/kaniko-project/executor:debug
17+
entrypoint: [""]
18+
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
20+
artifacts:
21+
paths:
22+
- build/
23+
expire_in: 1 days
24+
25+
image:scan:
26+
stage: scan
27+
image:
28+
name: sysdiglabs/secure-inline-scan:2
29+
entrypoint: [""]
30+
script:
31+
- mkdir reports
32+
- /sysdig-inline-scan.sh --sysdig-token $SYSDIG_SECURE_TOKEN --storage-type oci-dir --storage-path $(pwd)/build/ $CI_REGISTRY_NAME/$CI_IMAGE_NAME:$CI_IMAGE_TAG --report-folder reports
33+
artifacts:
34+
paths:
35+
- reports
36+
- build/
37+
expire_in: 1 days
38+
needs:
39+
- image:build
40+
41+
image:push:
42+
stage: push
43+
image:
44+
name: gcr.io/go-containerregistry/crane:debug
45+
entrypoint: [""]
46+
script:
47+
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY_HOST
48+
- crane push build/$CI_IMAGE_TAG.tar $CI_REGISTRY_HOST/$CI_REGISTRY_NAME/$CI_IMAGE_NAME:$CI_IMAGE_TAG
49+
needs:
50+
- image:scan

gitlab/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM alpine

gitlab/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# GitLab CI Demo - No DinD
2+
3+
![Gitlab job](/gitlab.png)
4+
5+
In this demo we will use GitLab pipelines without requiring privileged containers, or docker in docker.
6+
We will need to split this pipeline into three different jobs
7+
1. Kaniko: Tool used to build docker image
8+
2. Sysdig-inline-scan: Scan docker images for vulnerabilities
9+
3. Crane: Push container image to a remote registry
10+
11+
## Setup
12+
In GitLab repo settings add variables
13+
`CI_REGISTRY_USER`: Docker username
14+
`CI_REGISTRY_PASSWORD`: Docker user password
15+
`SYSDIG_SECURE_TOKEN`: Sysdig Token
16+
17+
Modify the gitlab-ci.yml file to build the image
18+
```
19+
CI_REGISTRY_HOST: "docker.io"
20+
CI_REGISTRY_NAME: my-registry
21+
CI_IMAGE_NAME: "my-image"
22+
CI_IMAGE_TAG: "latest"
23+
```
24+
25+
The variables are to build the full image url
26+
`$CI_REGISTRY_HOST/$CI_REGISTRY_NAME/$CI_IMAGE_NAME:$CI_IMAGE_TAG`
27+
We would expect
28+
`docker.io/my-registry/my-image:latest`
29+
30+
## Understanding the stages
31+
In order to get around using Docker in docker, these additional stages are necessary
32+
33+
There are three pipeline stages
34+
1. Build
35+
2. Scan
36+
3. Push
37+
38+
### Build
39+
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.
40+
We then save the `build/` directory as an artifact.
41+
42+
### Scan
43+
The scan stage is using `sysdig-inline-scan:2`. This stage uses a newer Sysdig scanning method without the docker daemon dependencies.
44+
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.
45+
46+
### Push
47+
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

gitlab/gitlab.png

136 KB
Loading

0 commit comments

Comments
 (0)