Skip to content

Commit a5e9f11

Browse files
committed
Add workflow to build Klocwork containers
1 parent ec42db4 commit a5e9f11

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
5+
6+
# This workflow combines a pull-request flow that only builds the container,
7+
# and a push flow that builds and pushes the container to the package registry.
8+
#
9+
# The push flow is triggered when the user pushes a commit to their personal,
10+
# forked repository; in this case the container image is uploaded to their
11+
# personal registry. The push flow is also triggered when a pull-request is
12+
# merged into the main branch; in this case the container image is uploaded
13+
# to the registry belonging to the runtime repository.
14+
#
15+
# This workflow design allows users to iterate and test container
16+
# changes in their forked repository, while ensuring that only merged
17+
# pull requests overwrite production images used by build workflows.
18+
19+
name: build container images
20+
21+
# https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/
22+
permissions:
23+
# Grant read permissions to repository in case it is not a forked public
24+
# repository, but a private repository that was created manually.
25+
contents: read
26+
27+
# If trigger-specific permissions were supported, write permissions to the
28+
# container registry would only be needed for push events.
29+
packages: write
30+
31+
on:
32+
push:
33+
branches:
34+
- main
35+
paths:
36+
- '.github/workflows/klocwork-container.yml'
37+
- 'container/ubuntu-20.04-klocwork-build-tools/**'
38+
- 'container/ubuntu-20.04-klocwork-desktop-tools/**'
39+
40+
pull_request:
41+
paths:
42+
- '.github/workflows/klocwork-container.yml'
43+
- 'container/ubuntu-20.04-klocwork-build-tools/**'
44+
- 'container/ubuntu-20.04-klocwork-desktop-tools/**'
45+
46+
workflow_dispatch:
47+
48+
jobs:
49+
build:
50+
runs-on:
51+
- self-hosted
52+
- linux
53+
- x64
54+
- container
55+
56+
# https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment
57+
environment: klocwork-container
58+
59+
# This rebuilds all container images whenever any single Dockerfile is
60+
# changed. Therefore, when iterating on a container change, consider
61+
# temporarily commenting all but the container of interest below.
62+
strategy:
63+
matrix:
64+
container:
65+
- ubuntu-20.04-klocwork-build-tools
66+
- ubuntu-20.04-klocwork-desktop-tools
67+
68+
env:
69+
image: ghcr.io/${{ github.repository }}/${{ matrix.container }}
70+
71+
KLOCWORK_BUILD_TOOLS_URL: ${{ secrets.KLOCWORK_BUILD_TOOLS_URL }}
72+
KLOCWORK_DESKTOP_TOOLS_URL: ${{ secrets.KLOCWORK_DESKTOP_TOOLS_URL }}
73+
KLOCWORK_LICENSE_SERVER: ${{ secrets.KLOCWORK_LICENSE_SERVER }}
74+
75+
continue-on-error: true
76+
77+
steps:
78+
- name: checkout code
79+
uses: actions/checkout@v3
80+
81+
# https://docs.docker.com/engine/reference/commandline/tag/#extended-description
82+
# > A tag name must be valid ASCII and may contain lowercase and
83+
# > uppercase letters, digits, underscores, periods and dashes.
84+
# > A tag name may not start with a period or a dash and may
85+
# > contain a maximum of 128 characters.
86+
- name: set container tag from git reference
87+
id: tag
88+
run: |
89+
ref=$(echo "$ref" | sed 's#^refs/\(\|heads/\|tags/\)##')
90+
echo "tag=${ref//[^a-zA-Z0-9_.]/-}" >> "$GITHUB_OUTPUT"
91+
env:
92+
ref: ${{ github.ref }}
93+
94+
# Override uid of default user in container to align with GitHub-hosted runners
95+
# https://github.com/actions/checkout/issues/47
96+
- name: build image
97+
run: |
98+
docker build \
99+
--build-arg uid=1001 \
100+
--build-arg klocwork_build_tools_url="$KLOCWORK_BUILD_TOOLS_URL" \
101+
--build-arg klocwork_desktop_tools_url="$KLOCWORK_DESKTOP_TOOLS_URL" \
102+
--build-arg klocwork_license_server="$KLOCWORK_LICENSE_SERVER" \
103+
-t "$image:$tag" -f container/${{ matrix.container }}/Dockerfile .
104+
env:
105+
tag: ${{ steps.tag.outputs.tag }}
106+
107+
- name: login to registry
108+
if: github.event_name == 'push'
109+
run: echo "$token" | docker login ghcr.io -u "$user" --password-stdin
110+
env:
111+
user: ${{ github.repository_owner }}
112+
token: ${{ secrets.GITHUB_TOKEN }}
113+
114+
- name: push image to registry
115+
if: github.event_name == 'push'
116+
run: docker image push "$image:$tag"
117+
env:
118+
tag: ${{ steps.tag.outputs.tag }}
119+
120+
- name: logout from registry
121+
if: always() && github.event_name == 'push'
122+
run: docker logout ghcr.io
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
5+
6+
FROM ubuntu:20.04
7+
8+
# Optionally override uid of default user in container, e.g.,
9+
# docker build --build-arg uid=1001 ...
10+
ARG uid
11+
12+
RUN \
13+
# Klocwork uses 32-bit binaries on x64_64
14+
dpkg --add-architecture i386 \
15+
&& apt-get -y update \
16+
&& DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade \
17+
build-essential \
18+
ca-certificates \
19+
cmake \
20+
curl \
21+
git \
22+
libarchive-tools \
23+
libelf-dev \
24+
libtinfo5 \
25+
libxml2 \
26+
ninja-build \
27+
sudo \
28+
zlib1g-dev \
29+
# faster compression for actions/cache
30+
zstd \
31+
# Klocwork specific dependencies below
32+
libc6:i386 \
33+
libgcc1:i386 \
34+
lib32tinfo6 \
35+
libncurses5:i386 \
36+
libncursesw5:i386 \
37+
libaio1 \
38+
numactl \
39+
lsb-core \
40+
&& apt-get -y clean \
41+
&& useradd --system ${uid:+--uid "$uid"} --user-group --shell /sbin/nologin --create-home --home-dir /home/klocwork klocwork \
42+
&& echo 'klocwork ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/klocwork
43+
44+
USER klocwork
45+
WORKDIR /home/klocwork
46+
47+
ARG klocwork_install_dir=/opt/klocwork
48+
ARG klocwork_build_tools_url
49+
ARG klocwork_desktop_tools_url
50+
ARG klocwork_license_server
51+
52+
RUN \
53+
sudo install -d -o klocwork -g klocwork "$klocwork_install_dir" \
54+
&& curl -L -o klocwork "$klocwork_build_tools_url" \
55+
&& bsdtar -xf klocwork --strip-components=1 -C "$klocwork_install_dir" \
56+
&& rm klocwork \
57+
&& sudo chown -R root:root "$klocwork_install_dir" \
58+
&& sudo chmod -R u=rwX,g=rX,o=rX "$klocwork_install_dir"
59+
60+
ENV PATH="$klocwork_install_dir/bin:$PATH"
61+
RUN kwbuildproject --version
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
5+
6+
FROM amr-cache-registry.caas.intel.com/cache/library/ubuntu:20.04
7+
8+
# Optionally override uid of default user in container, e.g.,
9+
# docker build --build-arg uid=1001 ...
10+
ARG uid
11+
12+
RUN \
13+
# Klocwork uses 32-bit binaries on x64_64
14+
dpkg --add-architecture i386 \
15+
&& apt-get -y update \
16+
&& DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade \
17+
build-essential \
18+
ca-certificates \
19+
cmake \
20+
curl \
21+
git \
22+
libarchive-tools \
23+
libelf-dev \
24+
libtinfo5 \
25+
libxml2 \
26+
ninja-build \
27+
sudo \
28+
zlib1g-dev \
29+
# faster compression for actions/cache
30+
zstd \
31+
# Klocwork specific dependencies below
32+
libc6:i386 \
33+
libgcc1:i386 \
34+
lib32tinfo6 \
35+
libncurses5:i386 \
36+
libncursesw5:i386 \
37+
libaio1 \
38+
numactl \
39+
lsb-core \
40+
&& apt-get -y clean \
41+
&& useradd --system ${uid:+--uid "$uid"} --user-group --shell /sbin/nologin --create-home --home-dir /home/klocwork klocwork \
42+
&& echo 'klocwork ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/klocwork
43+
44+
USER klocwork
45+
WORKDIR /home/klocwork
46+
47+
ARG klocwork_install_dir=/opt/klocwork
48+
ARG klocwork_build_tools_url
49+
ARG klocwork_desktop_tools_url
50+
ARG klocwork_license_server
51+
52+
RUN \
53+
sudo install -d -o klocwork -g klocwork "$klocwork_install_dir" \
54+
&& curl -L -o klocwork "$klocwork_desktop_tools_url" \
55+
&& chmod +x klocwork \
56+
&& ./klocwork --agree --license-server "$klocwork_license_server" "$klocwork_install_dir" \
57+
&& rm klocwork \
58+
&& sudo chown -R root:root "$klocwork_install_dir" \
59+
&& sudo chmod -R u=rwX,g=rX,o=rX "$klocwork_install_dir"
60+
61+
ENV PATH="$klocwork_install_dir/bin:$PATH"
62+
RUN kwcheck --version

0 commit comments

Comments
 (0)