Skip to content

Commit 0405cf9

Browse files
authored
ci: add release yml (#1)
* ci: add release yml * ci: remove codeql * ci: add helm chart * feat: automate mirror configuration * feat: make hosts configurable * fix: address toml issues * fix: address unit tests
1 parent 77365f8 commit 0405cf9

File tree

20 files changed

+404
-153
lines changed

20 files changed

+404
-153
lines changed

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+-alpha"
7+
8+
jobs:
9+
publish:
10+
name: Build and Publish Container Image
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
env:
16+
REGISTRY: ghcr.io
17+
REPO_PREFIX: ${{ format('{0}/acr/', github.repository_owner) }}
18+
19+
steps:
20+
- name: Get Git Tag
21+
id: get_git_tag
22+
run: echo ::set-output name=git_tag::${GITHUB_REF#refs/tags/}
23+
24+
- name: Check Out Source Code
25+
if: ${{ success() }}
26+
uses: actions/checkout@v2
27+
with:
28+
ref: ${{ steps.get_git_tag.outputs.git_tag }}
29+
30+
- name: Set Docker Image Tag
31+
env:
32+
GIT_TAG: ${{ steps.get_git_tag.outputs.git_tag }}
33+
id: get_image_tag
34+
run: echo ::set-output name=docker_tag::${GIT_TAG}
35+
36+
- name: Login to GitHub Container Registry
37+
uses: docker/login-action@v1
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Build Image
44+
if: ${{ success() }}
45+
run: |
46+
REGISTRY=${{ env.REGISTRY }} REPO_PREFIX=${{ env.REPO_PREFIX }} TAG=${{ steps.get_image_tag.outputs.docker_tag }} make build-image
47+
48+
- name: Push Image
49+
if: ${{ success() }}
50+
run: |
51+
docker push ${{ env.REGISTRY }}/${{ env.REPO_PREFIX }}peerd:${{ steps.get_image_tag.outputs.docker_tag }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ bin/**/*
2020

2121
# Go workspace file
2222
go.work
23+
24+
# Directories mounted to CI cluster.
25+
build/ci/configs/certs.d

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ TESTS_BIN_DIR = $(BIN_DIR)/tests
1515
COVERAGE_DIR=$(BIN_DIR)/coverage
1616
SCRIPTS_DIR=$(ROOT_DIR)/scripts
1717

18+
# Docker image variables.
19+
REGISTRY ?= localhost
20+
REPO_PREFIX ?=
21+
TAG ?= dev
22+
1823
include $(ROOT_DIR)/build/ci/Makefile
1924
include $(ROOT_DIR)/tests/Makefile
2025

@@ -109,13 +114,13 @@ header:
109114
# build-image-internal takes the dockerfile location, repository name and build context.
110115
# Example:
111116
define build-image-internal
112-
@echo "\033[92mBuilding Image: $2\033[0m"
117+
@echo "\033[92mBuilding image: $(REGISTRY)/$(REPO_PREFIX)$2:$(TAG)\033[0m"
113118

114119
@echo docker build -f $1 \
115-
-t localhost/$2:dev \
120+
-t $(REGISTRY)/$(REPO_PREFIX)$2:$(TAG) \
116121
$3
117122

118123
@docker build -f $1 \
119-
-t localhost/$2:dev \
124+
-t $(REGISTRY)/$(REPO_PREFIX)$2:$(TAG) \
120125
$3
121126
endef

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ This project implements peer to peer distribution of content (such as files or O
99
cluster. The source of the content could be another node in the same cluster, an OCI container registry (like Azure
1010
Container Registry) or a remote blob store (such as Azure Blob Storage).
1111

12+
#### Important Disclaimer
13+
14+
This project is work in progress and can be used for experimental and development purposes.
15+
It is not yet production ready, but we're getting there.
16+
1217
## Quickstart
1318

1419
This section shows how to get started with `peerd`.
@@ -46,6 +51,31 @@ tests-random-image Builds the 'random' tests image
4651
tests-scanner-image Builds the 'scanner' tests image
4752
```
4853
54+
### Deploy Helm Chart to your Cluster
55+
56+
If you already have a k8s cluster, you can deploy the `peerd` helm chart to it. With containerd, `peerd` leverages the
57+
[hosts configuration][containerd hosts] to act as a mirror for container images.
58+
59+
The `peerd` container image is available at `ghcr.io/azure/acr/peerd`.
60+
61+
```bash
62+
CLUSTER_CONTEXT=<your-cluster-context> && \
63+
HELM_RELEASE_NAME=peerd && \
64+
HELM_CHART_DIR=./build/ci/k8s/peerd-helm && \
65+
helm --kube-context=$CLUSTER_CONTEXT install --wait $HELM_RELEASE_NAME $HELM_CHART_DIR
66+
```
67+
68+
By default, only `mcr.microsoft.com` is mirrored, but this is configurable. For example, to configure `peerd` to mirror
69+
`mcr.microsoft.com` and `ghcr.io`, run the following.
70+
71+
```bash
72+
CLUSTER_CONTEXT=<your-cluster-context> && \
73+
HELM_RELEASE_NAME=peerd && \
74+
HELM_CHART_DIR=./build/ci/k8s/peerd-helm && \
75+
helm --kube-context=$CLUSTER_CONTEXT install --wait $HELM_RELEASE_NAME $HELM_CHART_DIR \
76+
--set peerd.hosts="mcr.microsoft.com ghcr.io"
77+
```
78+
4979
### Build and Deploy to a Local Kind Cluster
5080
5181
To build and deploy `peerd` to a 3 node kind cluster, run the following. These commands will build the `peerd`
@@ -228,3 +258,5 @@ A hat tip to:
228258
[swagger.yaml]: ./api/swagger.yaml
229259
[Spegel]: https://github.com/XenitAB/spegel
230260
[DADI P2P Proxy]: https://github.com/data-accelerator/dadi-p2proxy
261+
[containerd hosts]: https://github.com/containerd/containerd/blob/main/docs/hosts.md
262+
[containerd-mirror]: ./internal/containerd/mirror.go
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
server = "https://mcr.microsoft.com"
1+
server = 'https://mcr.microsoft.com'
22

3-
[host."https://localhost:30001"]
4-
capabilities = ["pull"]
5-
skip_verify = true
3+
[host]
4+
[host.'http://localhost:30001']
5+
capabilities = ['pull']

build/ci/k8s/app.yml

Lines changed: 0 additions & 78 deletions
This file was deleted.

build/ci/k8s/kind-cluster.yml

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,42 @@ kind: Cluster
22
apiVersion: kind.x-k8s.io/v1alpha4
33
name: p2p
44
nodes:
5-
- role: control-plane
6-
extraMounts:
7-
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
8-
containerPath: /etc/containerd/certs.d
5+
- role: control-plane
6+
extraMounts:
7+
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
8+
containerPath: /etc/containerd/certs.d
9+
- hostPath: $GIT_ROOT/build/ci/configs/containerd.toml
10+
containerPath: /etc/containerd/config.toml
911

10-
- role: worker
11-
labels:
12-
p2p-nodepool: 'true'
13-
extraMounts:
14-
- hostPath: $GIT_ROOT/bin/peerd
15-
containerPath: /bin/peerd
16-
- hostPath: $GIT_ROOT/bin/peerd.service
17-
containerPath: /bin/peerd.service
18-
- hostPath: $GIT_ROOT/bin/kind/metrics1
19-
containerPath: /var/log/
20-
- hostPath: $GIT_ROOT/build/ci/configs/containerd.toml
21-
containerPath: /etc/containerd/config.toml
22-
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
23-
containerPath: /etc/containerd/certs.d
12+
- role: worker
13+
labels:
14+
p2p-nodepool: "true"
15+
extraMounts:
16+
- hostPath: $GIT_ROOT/bin/kind/metrics1
17+
containerPath: /var/log/
18+
- hostPath: $GIT_ROOT/build/ci/configs/containerd.toml
19+
containerPath: /etc/containerd/config.toml
20+
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
21+
containerPath: /etc/containerd/certs.d
2422

25-
- role: worker
26-
labels:
27-
p2p-nodepool: 'true'
28-
extraMounts:
29-
- hostPath: $GIT_ROOT/bin/peerd
30-
containerPath: /bin/peerd
31-
- hostPath: $GIT_ROOT/bin/peerd.service
32-
containerPath: /bin/peerd.service
33-
- hostPath: $GIT_ROOT/bin/kind/metrics2
34-
containerPath: /var/log/
35-
- hostPath: $GIT_ROOT/build/ci/configs/containerd.toml
36-
containerPath: /etc/containerd/config.toml
37-
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
38-
containerPath: /etc/containerd/certs.d
23+
- role: worker
24+
labels:
25+
p2p-nodepool: "true"
26+
extraMounts:
27+
- hostPath: $GIT_ROOT/bin/kind/metrics2
28+
containerPath: /var/log/
29+
- hostPath: $GIT_ROOT/build/ci/configs/containerd.toml
30+
containerPath: /etc/containerd/config.toml
31+
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
32+
containerPath: /etc/containerd/certs.d
3933

40-
- role: worker
41-
labels:
42-
p2p-nodepool: 'true'
43-
extraMounts:
44-
- hostPath: $GIT_ROOT/bin/peerd
45-
containerPath: /bin/peerd
46-
- hostPath: $GIT_ROOT/bin/peerd.service
47-
containerPath: /bin/peerd.service
48-
- hostPath: $GIT_ROOT/bin/kind/metrics3
49-
containerPath: /var/log/
50-
- hostPath: $GIT_ROOT/build/ci/configs/containerd.toml
51-
containerPath: /etc/containerd/config.toml
52-
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
53-
containerPath: /etc/containerd/certs.d
34+
- role: worker
35+
labels:
36+
p2p-nodepool: "true"
37+
extraMounts:
38+
- hostPath: $GIT_ROOT/bin/kind/metrics3
39+
containerPath: /var/log/
40+
- hostPath: $GIT_ROOT/build/ci/configs/containerd.toml
41+
containerPath: /etc/containerd/config.toml
42+
- hostPath: $GIT_ROOT/build/ci/configs/certs.d
43+
containerPath: /etc/containerd/certs.d

build/ci/k8s/peerd-helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

build/ci/k8s/peerd-helm/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: peerd
3+
description: A Helm chart for peerd.
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.0.1-alpha
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "0.0.1-alpha"

0 commit comments

Comments
 (0)