Skip to content

Instantly share code, notes, and snippets.

@shokohsc
Created January 22, 2020 15:45
Show Gist options
  • Select an option

  • Save shokohsc/717b285c3cc131c378b3b2985d9fb101 to your computer and use it in GitHub Desktop.

Select an option

Save shokohsc/717b285c3cc131c378b3b2985d9fb101 to your computer and use it in GitHub Desktop.
Matrix docker build ci

ServiceCI

Create 'n' images by image tags & repository releases for one project

Dockerfile project example

ARG FROM_TAG='latest'
ARG OVERLAY_VERSION='v1.21.7.0'
ARG OVERLAY_ARCH='amd64'
FROM alpine:${FROM_TAG:-latest}
RUN ... && \
   curl -o /tmp/s6-overlay.tar.gz \
   -L "https://github.com/just-containers/s6-overlay/releases/download/${OVERLAY_VERSION}/s6-overlay-${OVERLAY_ARCH}.tar.gz" && \
   tar xzf /tmp/s6-overlay.tar.gz -C

Override 'from' image & tag on build with:

$> docker build \
   --build-arg FROM_TAG=alpine -t my_tag \
   .

Then do the same with each project dependency:

$> docker build \
   --build-arg FROM_TAG=alpine \
   --build-arg OVERLAY_VERSION=v1.22.1.0 \
   --build-arg OVERLAY_ARCH=amd64 -t my_tag \
   .

Ci file example

build-args:
    tags:
        key: FROM_TAG
        author: library
        image: alpine
        offset: 0
        limit: 3
    releases:
        - key: OVERLAY_VERSION
          author: just-containers
          repository: s6-overlay
          offset: 0
          limit: 3
    fixed:
        - key: OVERLAY_ARCH
          value: amd64
          tag_key: arch

ServiceCI <-> Sidekick communication

sequenceDiagram
ServiceCI ->> Sidekick: GET /api/docker/author/image/?limit=2
loop every page
    Sidekick->>ContainerRegistry: curl registry_url/tags/?page=n
end
Note over Sidekick,ContainerRegistry: Promise.all() to save time
ContainerRegistry ->> Sidekick: response
Sidekick ->> ServiceCI: response 2 last tags
ServiceCI ->> Sidekick: GET /api/git/author/repository/?limit=2
Sidekick ->> GitServer: git ls-remote
GitServer ->> Sidekick: response
Sidekick ->> ServiceCI: response 2 last releases
loop every tag
    loop every release
        ServiceCI->>ServiceCISlave: docker build tag:release
        ServiceCI->>ServiceCISlave: test 0 = $? && docker run -d --rm --name project tag:release
        ServiceCI->>ServiceCISlave: test 0 = $? && docker rm -f project
        ServiceCI->>ServiceCISlave: test 0 = $? && docker push project:tag-release
    end
end
Loading

Steps

1: Request from ServiceCI to Sidekick

$> curl http://sidekick/api/docker?author=library&image=alpine&limit=2

2: Request from Sidekick to ContainerRegistry

$> curl registry/author/image/tags | jq '."results"[]["name"]'

3: Response from ContainerRegistry to Sidekick

"3.11.3"
"3.11"
"3"
"3.11.2"
"edge"
"3.11.0"
"20191219"
"20191114"
"3.10.3"
"3.10"
"20190925"
...

4: Response from Sidekick to ServiceCI

{
  tags: [
    "3.11.3",
    "3.11"
  ]
}

5: Request from ServiceCI to Sidekick

$> curl http://sidekick/api/git?author=just-containers&repository=s6-overlay&limit=3

6: Request from Sidekick to GitServer

$> git ls-remote --heads --sort=v:refname \
https://github.com/just-containers/s6-overlay.git |\
grep -v '{}' |\
sed 's/.*refs\/heads\///; s/\^{}//'

$> git ls-remote --tags --sort=v:refname \
https://github.com/just-containers/s6-overlay.git |\
grep -v '{}' |\
sed 's/.*\///; s/\^{}//'

7: Response from GitServer to Sidekick

0baa2015adb79bca863f3c3bdf0deb7796182f61	refs/heads/issue-244
3ead812d235c853dee2f47497399353da3111163	refs/heads/issue-246
fca73dc6d74708554702759ac168e5e3fd68662f	refs/heads/master

ae58a94c252f1e17041a522ea2a10391aba5eba9	refs/tags/v1.9.1.0
3191849d037303e95667f0a192cbb99644ab8c5e	refs/tags/v1.9.1.0^{}
a1213f3bb0b4680747edfe682b188e7d103d96de	refs/tags/v1.9.1.1
1977861e726727fccb1dae25ff66edd75181604d	refs/tags/v1.9.1.1^{}
7a07ad9a4bf53c19c72b986e5f76f93907284c5a	refs/tags/v1.9.1.2
e37db7c4702f4665b67b340419ddb1a73f161770	refs/tags/v1.9.1.2^{}
c641e39165286b59e29862db9a6d64abba9c0046	refs/tags/v1.9.1.3
8775ae7a50497d6218ed43b9210c9c79de82c6b3	refs/tags/v1.9.1.3^{}
...

8: Response from Sidekick to ServiceCI

{
  branches: [
    "issue-244",
    "issue-246"
  ],
  releases: [
    "v1.22.1.0",
    "v1.22.0.0",
    "v1.21.8.0"
  ]
}

9: Build from ServiceCI to ServiceCISlave

$> docker build \
   --build-arg FROM_TAG=3.11.3 \
   --build-arg OVERLAY_VERSION=v1.22.1.0 \
   --build-arg OVERLAY_ARCH=amd64 \
   -t author/project:alpine-3.11.3-s6-overlay-v1.22.1.0-arch-amd64 \
   .

10: Build from ServiceCI to ServiceCISlave

$> docker build \
   --build-arg FROM_TAG=3.11.3 \
   --build-arg OVERLAY_VERSION=v1.22.0.0 \
   --build-arg OVERLAY_ARCH=amd64 \
   -t author/project:alpine-3.11.3-s6-overlay-v1.22.0.0-arch-amd64 \
   .

11: Build from ServiceCI to ServiceCISlave

$> docker build \
   --build-arg FROM_TAG=3.11.3 \
   --build-arg OVERLAY_VERSION=v1.21.8.0 \
   --build-arg OVERLAY_ARCH=amd64 \
   -t author/project:alpine-3.11.3-s6-overlay-v1.21.8.0-arch-amd64 \
   .

n: Build from ServiceCI to ServiceCISlave

$> docker build \
   --build-arg FROM_TAG=3.11 \
   --build-arg OVERLAY_VERSION=v1.22.1.0 \
   --build-arg OVERLAY_ARCH=amd64 \
   -t author/project:alpine-3.11-s6-overlay-v1.22.1.0-arch-amd64 \
   .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment