Skip to content

Commit 9103331

Browse files
authored
Merge pull request #191 from marquiz/devel/plugin-images
Publish sample plugin container images
2 parents 3571db8 + fc7d649 commit 9103331

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

.dockerignore

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

.github/workflows/images.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Publish Container Images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- v[0-9]+.[0-9]+.[0-9]+
9+
pull_request:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
jobs:
20+
build-and-push:
21+
name: Build and Push (${{ matrix.image }})
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
image: [
26+
device-injector,
27+
differ,
28+
hook-injector,
29+
logger,
30+
network-device-injector,
31+
network-logger,
32+
template,
33+
ulimit-adjuster,
34+
v010-adapter,
35+
]
36+
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v4
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Log in to registry
45+
if: github.event_name == 'push'
46+
uses: docker/login-action@v3
47+
with:
48+
registry: ghcr.io
49+
username: ${{ github.actor }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Determine image tag name
53+
id: tag
54+
run: |
55+
if [ "${{ github.ref_type }}" = "tag" ]; then
56+
tag="${{ github.ref_name }}"
57+
else
58+
if [ "${{ github.event_name }}" = "pull_request" ]; then
59+
tag="pr-${{ github.event.pull_request.number }}"
60+
else
61+
case "${{ github.ref_name }}" in
62+
main)
63+
tag="unstable"
64+
;;
65+
esac
66+
fi
67+
fi
68+
if [ -z "$tag" ]; then
69+
echo "ERROR: failed to determine image tag"
70+
exit 1
71+
fi
72+
echo "TAG_NAME=$tag" >> $GITHUB_ENV
73+
74+
- name: Build and push image
75+
uses: docker/build-push-action@v6
76+
with:
77+
context: .
78+
file: ./plugins/Dockerfile
79+
build-args: |
80+
PLUGIN=${{ matrix.image }}
81+
push: ${{ github.event_name == 'push' }}
82+
platforms: ${{ github.event_name == 'push' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
83+
tags: ghcr.io/${{ github.repository }}/plugins/${{ matrix.image }}:${{ env.TAG_NAME }}

plugins/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright The containerd Authors.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG GO_VERSION=1.24
16+
17+
FROM golang:${GO_VERSION}-bullseye AS builder
18+
ARG PLUGIN
19+
20+
WORKDIR /go/src
21+
22+
# Cache dependencies in a separate layer
23+
COPY go.mod go.sum .
24+
RUN --mount=type=cache,target=/go/pkg/mod/ go mod download
25+
26+
# Build
27+
COPY . .
28+
29+
RUN --mount=type=cache,target=/go/pkg/mod/ \
30+
make /go/src/build/bin/${PLUGIN} \
31+
GO_BUILD="CGO_ENABLED=0 go build -ldflags '-extldflags=-static'"
32+
33+
# Construct final image
34+
FROM scratch
35+
ARG PLUGIN
36+
37+
COPY --from=builder /go/src/build/bin/${PLUGIN} /bin/plugin
38+
39+
ENV NRI_PLUGIN_NAME=${PLUGIN}
40+
41+
ENTRYPOINT ["/bin/plugin"]

0 commit comments

Comments
 (0)