-
Notifications
You must be signed in to change notification settings - Fork 19
161 lines (142 loc) · 5.38 KB
/
container-publish-ghcr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Publish GHCR Container
# Publish a multi-platform container when a version is tagged
on:
workflow_dispatch:
push:
tags:
- 'v*.*.*'
env:
REGISTRY: ghcr.io
IMAGE_NAME_BASE: scanoss/scanoss-py-base
IMAGE_NAME: scanoss/scanoss-py
IMAGE_JENKINS: scanoss/scanoss-py-jenkins
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# Setup and build python package
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10.x'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Build package
run: make dist
# Add support for more platforms with QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Workaround: https://github.com/docker/build-push-action/issues/461
# uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata - no entrypoint
id: meta-ne
uses: docker/metadata-action@v4
with:
images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BASE }}"
# Build and push Docker image with Buildx (don't push on PR)
- name: Build and push Docker image - Base (no entrypoint)
id: build-and-push-ne
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-ne.outputs.tags }}
labels: ${{ steps.meta-ne.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
target: no_entry_point
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata - jenkins
id: meta-je
uses: docker/metadata-action@v4
with:
images: "${{ env.REGISTRY }}/${{ env.IMAGE_JENKINS }}"
# Build and push Docker image with Buildx (don't push on PR)
- name: Build and push Docker image - Jenkins
id: build-and-push-je
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-je.outputs.tags }}
labels: ${{ steps.meta-je.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
target: jenkins
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata - entrypoint
id: meta
uses: docker/metadata-action@v4
with:
images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
# Build and push Docker image with Buildx (don't push on PR)
- name: Build and push Docker image - EP (entrypoint)
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
target: with_entry_point
# Test the docker image
- name: Test Published Image
if: github.event_name != 'pull_request'
run: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker run ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} version
docker run ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} utils fast
docker run -v "$(pwd)":"/scanoss" ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} scan -o results.json tests
id_count=$(cat results.json | grep '"id":' | wc -l)
echo "ID Count: $id_count"
if [[ $id_count -lt 1 ]]; then
echo "Error: Scan test did not produce any results. Failing"
exit 1
fi
# Install the cosign tool except on PR
# - name: Install cosign
# if: github.event_name != 'pull_request'
# uses: sigstore/cosign-installer@v2
#
# - name: Check Cosign Version
# run: cosign version
#
# - name: Sign Docker Image
# if: ${{ github.event_name != 'pull_request' }}
# env:
# TAGS: ${{ steps.meta.outputs.tags }}
# COSIGN_PRIVATE_KEY: ${{secrets.COSIGN_PRIVATE_KEY}}
# COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}
# run: cosign sign --key env://COSIGN_PRIVATE_KEY --no-tlog-upload=true ${TAGS}
# - name: Sign the images with GitHub OIDC Token
# run: cosign sign ${TAGS}
# env:
# TAGS: ${{ steps.meta.outputs.tags }}
# COSIGN_EXPERIMENTAL: true