Skip to content

Commit

Permalink
on-tag improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
meeDamian committed Jan 23, 2020
1 parent 9f2c30c commit 7725522
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 51 deletions.
108 changes: 71 additions & 37 deletions .github/workflows/on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ jobs:
QEMU_VERSION: v4.2.0
run: docker run --rm --privileged "meedamian/simple-qemu:${QEMU_VERSION}" -p yes

# TODO: add labels, see: https://github.com/lncm/docker-lnd/blob/3a26bc667c441e94958b876170f87d538cb5a07a/.github/workflows/on-tag.yml#L102-L107
- name: Build IPFS
run: >
docker build --no-cache .
Expand All @@ -111,6 +110,12 @@ jobs:
--build-arg "GOARCH=${GOARCH}"
--build-arg "GOARM=${GOARM}"
--build-arg "FLAVOR=${{matrix.flavor}}"
--label "arch=${{matrix.arch}}"
--label "commit=${{github.sha}}"
--label "git-tag=${TAG}"
--label "guilty=${{github.actor}}"
--label "repo-url=${{github.repositoryUrl}}"
--label "flavor=${FLAVOR}"
--tag "${APP}:${FLAV_ARCH}"
- name: Show built image details
Expand Down Expand Up @@ -148,34 +153,48 @@ jobs:
path: binary/


docker-hub-push:
name: Tag & deploy to Docker Hub. Only after successful build, and test of a pushed git tag
docker-hub:
name: Tag & deploy to Docker Hub. Only after all builds & tests succeed

runs-on: ubuntu-18.04
needs: build

env:
APP: ipfs

steps:
- uses: actions/[email protected]

- name: Enable Docker manifest features
run: |
mkdir -p ~/.docker
echo '{ "experimental": "enabled" }' > ~/.docker/config.json
sudo systemctl restart docker
- name: Setup environment
run: |
VERSION="$(echo "${GITHUB_REF}" | grep 'refs/tags/' | awk -F/ '{print $NF}')"
echo ::set-env name=VERSION::"${VERSION}"
echo ::set-env name=DOCKER_USER::"${GITHUB_ACTOR,,}"
SLUG="$(echo ${GITHUB_REPOSITORY,,} | sed 's/docker-//')"
echo ::set-env name=SLUG::"${SLUG}"
echo ::set-env name=SLUG::"$(echo ${GITHUB_REPOSITORY,,} | sed 's/docker-//')"
echo ::set-env name=APP::"$(echo "${SLUG}" | awk -F/ '{print $NF}')"
- name: Print Docker version
run: docker version
TAG="$(echo "${GITHUB_REF}" | grep 'refs/tags/' | awk -F/ '{print $NF}')"
echo ::set-env name=TAG::"${TAG}"
- name: Download build artifact
echo ::set-env name=VERSION::"$(echo "${TAG}" | cut -d+ -f1)"
echo ::set-env name=BUILD::"$(echo "+${TAG}" | cut -d+ -f3)"
- name: Print just set ENV VARs
run: |
printf "Just set env vars:\n"
printf " USER: %s\n" "${DOCKER_USER}"
printf " TAG: %s\n" "${TAG}"
printf " SLUG: %s\n" "${SLUG}"
printf " APP: %s\n" "${APP}"
printf "VERSION: %s\n" "${VERSION}"
printf " BUILD: %s\n" "${BUILD}"
- name: Enable manifests & print Docker version
run: |
mkdir -p ~/.docker
echo '{ "experimental": "enabled" }' > ~/.docker/config.json
sudo systemctl restart docker
docker version
- name: Download images built in build job
uses: actions/[email protected]
with:
name: docker-images
Expand All @@ -184,47 +203,62 @@ jobs:
run: sha256sum docker-images/*

- name: Load images locally
run: ls docker-images/ | xargs -I % docker load -i "docker-images/%"

- name: List all tagged images
run: docker images "${APP}"
run: ls -d docker-images/* | xargs -I % docker load -i "%"

# `ipfs:fuse-arm64` -> `lncm/ipfs:v0.4.22-fuse-arm64-build1`
# `ipfs:fuse-arm64` -> `lncm/ipfs:v0.4.22-fuse-arm64`
# `ipfs:nofuse-arm64` -> `lncm/ipfs:v0.4.22-nofuse-arm64-build1`
# `ipfs:nofuse-arm64 -> `lncm/ipfs:v0.4.22-nofuse-arm64`
- name: Version-tag all images
run: |
for arch in $(docker images "${APP}" --format "{{.Tag}}"); do
docker tag "${APP}:${arch}" "${SLUG}:${VERSION}-${arch}"
for tag in $(docker images ${APP} --format "{{.Tag}}"); do
docker tag "${APP}:${tag}" "${SLUG}:${VERSION}-${tag}-${BUILD}"
docker tag "${APP}:${tag}" "${SLUG}:${VERSION}-${tag}"
done
- name: List all tagged images
run: docker images "${SLUG}"

- name: Login to Docker Hub
run: echo "${{secrets.DOCKER_TOKEN}}" | docker login -u="meedamian" --password-stdin
run: |
echo "Logging in as ${DOCKER_USER}…"
echo "${{secrets.DOCKER_TOKEN}}" | docker login -u="${DOCKER_USER}" --password-stdin
- name: Push all images
run: |
for image in $(docker images "${SLUG}" --format "{{.Repository}}:{{.Tag}}"); do
docker push "${image}"
done
run: docker images "${SLUG}" --format "{{.Repository}}:{{.Tag}}" | xargs -I % docker push %

- name: Get convenience Docker tag suggestions
id: tags
uses: meeDamian/[email protected]

- name: Create version-exact manifest
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}"
- name: Create :X.Y.Z manifests
run: |
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "${VERSION}-fuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${VERSION}-nofuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse"
- name: Create minor-version manifest
- name: Create :X.Y manifests
if: steps.tags.outputs.minor != ''
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "${{steps.tags.outputs.minor}}"
run: |
SHORT="${{steps.tags.outputs.minor}}"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "${SHORT}-fuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${SHORT}-nofuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse"
- name: Create major-version manifest
- name: Create :X manifests
if: steps.tags.outputs.major != ''
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "${{steps.tags.outputs.major}}"
run: |
SHORT="${{steps.tags.outputs.major}}"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "${SHORT}-fuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${SHORT}-nofuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse"
- name: Create latest-version manifest
- name: Create :latest manifests
if: steps.tags.outputs.latest != ''
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "${{steps.tags.outputs.latest}}"
run: |
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "fuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "nofuse"
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${{steps.tags.outputs.latest}}"
- name: List all tagged images
run: docker images "${SLUG}"
Expand Down
25 changes: 11 additions & 14 deletions scripts/ci-create-manifest.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#!/bin/bash
set -e
#!/usr/bin/env bash

set -eo pipefail

SLUG=$1
VERSION=$2
FLAVOR=$3
SHORT_VERSION=${4:-${VERSION}}

SHORT_VERSION=$3
if [[ -z "${SHORT_VERSION}" ]]; then
SHORT_VERSION="${VERSION}"
fi

BASE="${SLUG}:${VERSION}"

IMAGE_AMD64="${BASE}-linux-amd64"
IMAGE_ARM64="${BASE}-linux-arm64"
IMAGE_ARM6="${BASE}-linux-arm32v6"
IMAGE_ARM7="${BASE}-linux-arm32v7"
BASE="${SLUG}:${VERSION}-${FLAVOR}"

IMAGE_AMD64="${BASE}-amd64"
IMAGE_ARM64="${BASE}-arm64"
IMAGE_ARM6="${BASE}-arm32v6"
IMAGE_ARM7="${BASE}-arm32v7"

MANIFEST="${SLUG}:${SHORT_VERSION}"

docker -D manifest create "${MANIFEST}" "${IMAGE_AMD64}" "${IMAGE_ARM64}" "${IMAGE_ARM6}" "${IMAGE_ARM7}"
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM64}" --os linux --arch arm64
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM64}" --os linux --arch arm64 --variant v8
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM7}" --os linux --arch arm --variant v7
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM6}" --os linux --arch arm --variant v6
docker manifest push "${MANIFEST}"

0 comments on commit 7725522

Please sign in to comment.