Skip to content

Commit 38b0297

Browse files
authored
Added github action (#22)
1 parent 3539982 commit 38b0297

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ In this [repository](https://github.com/sysdiglabs/secure-inline-scan-examples/)
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)
139139
* [Gitlab](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/gitlab)
140+
* [GitHub](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/github)
140141
* [Tekton](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/tekton)
141142
* [Tekton alpha API](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/tekton/alpha)
142143
* [Tekton beta API](https://github.com/sysdiglabs/secure-inline-scan-examples/tree/main/tekton/beta)

github/Dockerfile

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

github/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# GitHub CI Demo
2+
3+
In this demo we will use GitHub actions to build, scan and push a container image.
4+
The workflow is as follows:
5+
6+
1. Setup Docker Buildx to be able to build the image
7+
2. Build the container image and store it locally
8+
3. Download the sysdig-cli-scanner cli if needed
9+
4. Perform the scan
10+
5. Login to the registry
11+
6. Push the container image to a remote registry
12+
13+
The workflow leverages GitHub actions cache to avoid downloading the binary or
14+
the databases if they are available.
15+
16+
## Setup
17+
18+
It is required to create a few repository secrets in order to be able to push the
19+
container image:
20+
21+
* `REGISTRY_USER`: Docker username
22+
* `REGISTRY_PASSWORD`: Docker user password
23+
* `SECURE_API_TOKEN`: Sysdig Token
24+
25+
Modify the environment variables on the [build-scan-and-push.yaml](build-scan-and-push.yaml) file to fit your needs:
26+
27+
```
28+
SYSDIG_SECURE_ENDPOINT: "https://secure.sysdig.com"
29+
REGISTRY_HOST: "quay.io"
30+
IMAGE_NAME: "mytestimage"
31+
IMAGE_TAG: "my-tag"
32+
DOCKERFILE_CONTEXT: "github/"
33+
```

github/build-scan-and-push.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
env:
2+
SYSDIG_SECURE_ENDPOINT: "https://eu1.app.sysdig.com"
3+
REGISTRY_HOST: "quay.io"
4+
IMAGE_NAME: "mytestimage"
5+
IMAGE_TAG: "my-tag"
6+
DOCKERFILE_CONTEXT: "github/"
7+
8+
name: Container build, scan and push
9+
10+
on: [push, pull_request]
11+
12+
jobs:
13+
build-scan-and-push:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
22+
- name: Build and save
23+
uses: docker/build-push-action@v3
24+
with:
25+
context: ${{ env.DOCKERFILE_CONTEXT }}
26+
tags: ${{ env.REGISTRY_HOST }}/${{ secrets.REGISTRY_USER }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
27+
load: true
28+
29+
- name: Setup cache
30+
uses: actions/cache@v3
31+
with:
32+
path: cache
33+
key: ${{ runner.os }}-cache-${{ hashFiles('**/sysdig-cli-scanner', '**/latest_version.txt', '**/db/main.db.meta.json', '**/scanner-cache/inlineScannerCache.db') }}
34+
restore-keys: ${{ runner.os }}-cache-
35+
36+
- name: Download sysdig-cli-scanner if needed
37+
run: |
38+
curl -sLO https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt
39+
mkdir -p ${GITHUB_WORKSPACE}/cache/db/
40+
if [ ! -f ${GITHUB_WORKSPACE}/cache/latest_version.txt ] || [ $(cat ./latest_version.txt) != $(cat ${GITHUB_WORKSPACE}/cache/latest_version.txt) ]; then
41+
cp ./latest_version.txt ${GITHUB_WORKSPACE}/cache/latest_version.txt
42+
curl -sL -o ${GITHUB_WORKSPACE}/cache/sysdig-cli-scanner "https://download.sysdig.com/scanning/bin/sysdig-cli-scanner/$(cat ${GITHUB_WORKSPACE}/cache/latest_version.txt)/linux/amd64/sysdig-cli-scanner"
43+
chmod +x ${GITHUB_WORKSPACE}/cache/sysdig-cli-scanner
44+
else
45+
echo "sysdig-cli-scanner latest version already downloaded"
46+
fi
47+
48+
- name: Scan the image using sysdig-cli-scanner
49+
env:
50+
SECURE_API_TOKEN: ${{ secrets.SECURE_API_TOKEN }}
51+
run: |
52+
${GITHUB_WORKSPACE}/cache/sysdig-cli-scanner \
53+
--apiurl ${SYSDIG_SECURE_ENDPOINT} \
54+
docker://${REGISTRY_HOST}/${{ secrets.REGISTRY_USER }}/${IMAGE_NAME}:${IMAGE_TAG} \
55+
--console-log \
56+
--dbpath=${GITHUB_WORKSPACE}/cache/db/ \
57+
--cachepath=${GITHUB_WORKSPACE}/cache/scanner-cache/
58+
59+
- name: Login to the registry
60+
uses: docker/login-action@v2
61+
with:
62+
registry: ${{ env.REGISTRY_HOST }}
63+
username: ${{ secrets.REGISTRY_USER }}
64+
password: ${{ secrets.REGISTRY_PASSWORD }}
65+
66+
- name: Push
67+
uses: docker/build-push-action@v3
68+
with:
69+
context: ${{ env.DOCKERFILE_CONTEXT }}
70+
push: true
71+
tags: ${{ env.REGISTRY_HOST }}/${{ secrets.REGISTRY_USER }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}

0 commit comments

Comments
 (0)