Skip to content

Commit 096f388

Browse files
committed
Scan Docker images in Snyk Github action (close #285)
1 parent f24499b commit 096f388

File tree

3 files changed

+125
-92
lines changed

3 files changed

+125
-92
lines changed

.github/workflows/ci.yml

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
branches:
8+
- master
9+
- develop
10+
pull_request:
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Set up JDK 11
20+
uses: actions/setup-java@v2
21+
with:
22+
java-version: 11
23+
distribution: adopt
24+
25+
- name: Install LZO
26+
run: sudo apt-get install -y lzop liblzo2-dev
27+
28+
- name: Run tests
29+
run: |
30+
sbt "project main" test
31+
sbt "project lzo" test
32+
33+
- name: Check formatting
34+
run: sbt scalafmtCheck
35+
36+
publish_docker:
37+
needs: test
38+
if: startsWith(github.ref, 'refs/tags/')
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
app:
43+
- main
44+
- lzo
45+
- distroless
46+
include:
47+
- suffix: ""
48+
- app: lzo
49+
run_snyk: ${{ !contains(github.ref, 'rc') }}
50+
- app: distroless
51+
run_snyk: ${{ !contains(github.ref, 'rc') }}
52+
53+
steps:
54+
- uses: actions/checkout@v2
55+
56+
- name: Set up JDK 11
57+
uses: actions/setup-java@v2
58+
with:
59+
java-version: 11
60+
distribution: adopt
61+
62+
- name: Install LZO
63+
run: sudo apt-get install -y lzop liblzo2-dev
64+
65+
- name: Login to Docker Hub
66+
if: startsWith(github.ref, 'refs/tags/')
67+
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
68+
env:
69+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
70+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
71+
72+
- name: Publish to Docker Hub
73+
if: startsWith(github.ref, 'refs/tags/')
74+
run: sbt "project ${{ matrix.app }}" docker:publish
75+
76+
- name: Build local image, which is needed to run Snyk
77+
if: matrix.run_snyk
78+
run: sbt "project ${{ matrix.app }}" docker:publishLocal
79+
- name: Run Snyk to check for vulnerabilities
80+
uses: snyk/actions/docker@master
81+
if: matrix.run_snyk
82+
with:
83+
image: "snowplow/snowplow-s3-loader:${{ github.ref_name }}-${{ matrix.app }}"
84+
args: "--app-vulns --org=data-processing-new"
85+
command: monitor
86+
env:
87+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
88+
89+
create_release:
90+
needs: test
91+
if: ${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'rc') }}
92+
runs-on: ubuntu-latest
93+
94+
steps:
95+
- uses: actions/checkout@v2
96+
97+
- name: Set up JDK 11
98+
uses: actions/setup-java@v2
99+
with:
100+
java-version: 11
101+
distribution: adopt
102+
103+
- name: Install LZO
104+
run: sudo apt-get install -y lzop liblzo2-dev
105+
106+
- name: Build artifacts
107+
run: |
108+
sbt assembly
109+
- name: Get current version
110+
id: ver
111+
run: |
112+
export PROJECT_VERSION=$(sbt version -Dsbt.log.noformat=true | perl -ne 'print "$1\n" if /info.*(\d+\.\d+\.\d+[^\r\n]*)/' | tail -n 1 | tr -d '\n')
113+
echo "::set-output name=project_version::$PROJECT_VERSION"
114+
- name: Create GitHub release and attach artifacts
115+
uses: softprops/action-gh-release@v1
116+
with:
117+
draft: true
118+
prerelease: true
119+
name: Version ${{ steps.ver.outputs.project_version }}
120+
tag_name: ${{ steps.ver.outputs.project_version }}
121+
files: |
122+
modules/main/target/scala-2.13/snowplow-s3-loader-${{ steps.ver.outputs.project_version }}.jar
123+
modules/lzo/target/scala-2.13/snowplow-s3-loader-lzo-${{ steps.ver.outputs.project_version }}.jar
124+
env:
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/snyk.yml

-20
This file was deleted.

.github/workflows/test_and_publish.yml

-72
This file was deleted.

0 commit comments

Comments
 (0)