From 94094bafe7c9aebf39b22b8f28308814f449a455 Mon Sep 17 00:00:00 2001 From: Derek Yeh Date: Wed, 14 Jul 2021 18:11:46 -0700 Subject: [PATCH 1/6] Update and rename utils.sh to .github/workflows/utils.sh --- .github/workflows/utils.sh | 112 +++++++++++++++++++++++++++++++++++ utils.sh | 118 ------------------------------------- 2 files changed, 112 insertions(+), 118 deletions(-) create mode 100755 .github/workflows/utils.sh delete mode 100755 utils.sh diff --git a/.github/workflows/utils.sh b/.github/workflows/utils.sh new file mode 100755 index 00000000..eef53026 --- /dev/null +++ b/.github/workflows/utils.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +get_variant_sha(){ + local sha + docker_repo=$1 #alpine or vmnet/alpine + manifest_tag=$2 + docker_image=$docker_repo:$manifest_tag + arch=$3 + variant=$4 + export DOCKER_CLI_EXPERIMENTAL=enabled + + docker pull -q ${docker_image} &>/dev/null + docker manifest inspect ${docker_image} > "$2".txt + + sha="" + i=0 + while [ "$sha" == "" ] && read -r line + do + arch=$(jq .manifests[$i].platform.architecture "$2".txt |sed -e 's/^"//' -e 's/"$//') + if [ "$arch" = "$3" ] && [ "$arch" != "arm" ]; then + sha=$(jq .manifests[$i].digest "$2".txt |sed -e 's/^"//' -e 's/"$//') + echo ${sha} + elif [ "$arch" = "$3" ]; then + variant=$(jq .manifests[$i].platform.variant "$2".txt |sed -e 's/^"//' -e 's/"$//') + if [ "$variant" == "$4" ]; then + sha=$(jq .manifests[$i].digest "$2".txt |sed -e 's/^"//' -e 's/"$//') + echo ${sha} + fi + fi + i=$i+1 + done < "$2".txt +} + +get_manifest_sha (){ + local repo=$1 + local arch=$2 + docker pull -q $1 &>/dev/null + docker manifest inspect $1 > "$2".txt + sha="" + i=0 + while [ "$sha" == "" ] && read -r line + do + archecture=$(jq .manifests[$i].platform.architecture "$2".txt |sed -e 's/^"//' -e 's/"$//') + if [ "$archecture" = "$2" ];then + sha=$(jq .manifests[$i].digest "$2".txt |sed -e 's/^"//' -e 's/"$//') + echo ${sha} + fi + i=$i+1 + done < "$2".txt +} + +get_tag_sha(){ + local repo=$1 + local tag=$2 + docker pull "$repo:$tag" &>/dev/null + sha=$(docker inspect --format='{{index .RepoDigests 0}}' "$repo:$tag" 2>/dev/null | cut -d @ -f 2) + echo $sha +} + +build_image(){ + local repo=$1 # this is the base repo, for example treehouses/alpine + local arch=$2 #arm arm64 amd64 + local tag_repo=$3 # this is the tag repo, for example treehouses/node + if [ $# -le 1 ]; then + echo "missing parameters." + exit 1 + fi + sha=$(get_manifest_sha $@) + echo $sha + base_image="$repo@$sha" + echo $base_image + if [ -n "$sha" ]; then + tag=$tag_repo-tags:$arch + sed "s|{{base_image}}|$base_image|g" Dockerfile.template > Dockerfile.$arch + docker buildx build --platform linux/$arch -t $tag -f Dockerfile.$arch . + fi +} + +deploy_image(){ + local repo=$1 + local arch=$2 #arm arm64 amd64 + tag_arch=$repo-tags:$arch + tag_time=$(date +%Y%m%d%H%M) + tag_arch_time=$repo-tags:$arch-$tag_time + echo $tag_arch_time + docker tag $tag_arch $tag_arch_time + docker push $tag_arch_time + docker tag $tag_arch_time $tag_arch + docker push $tag_arch +} + +compare_sha () { + if [ "$1" != "$2" ] || [ "$3" != "$4" ] || [ "$5" != "$6" ]; then + echo "true" + else + echo "false" + fi +} + +create_manifests(){ + local repo=$1 + local tag=$2 + local x86=$3 + local rpi=$4 + local arm64=$5 + docker manifest create $repo:$tag $x86 $rpi $arm64 + docker manifest create $repo:latest $x86 $rpi $arm64 + docker manifest annotate $repo:latest $rpi --arch arm + docker manifest annotate $repo:$tag $arm64 --arch arm64 + docker manifest annotate $repo:latest $arm64 --arch arm64 + docker manifest annotate $repo:$tag $rpi --arch arm +} diff --git a/utils.sh b/utils.sh deleted file mode 100755 index a365f9d7..00000000 --- a/utils.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -get_manifest_sha() { - local repo=$1 - local arch=$2 - docker pull -q $1 &>/dev/null - docker manifest inspect $1 > "$2".txt - sha="" - i=0 - while [ "$sha" == "" ] && read -r line; do - architecture=$(jq .manifests[$i].platform.architecture "$2".txt |sed -e 's/^"//' -e 's/"$//') - if [ "$architecture" = "$2" ];then - sha=$(jq .manifests[$i].digest "$2".txt |sed -e 's/^"//' -e 's/"$//') - echo ${sha} - fi - i=$i+1 - done < "$2".txt -} - -get_sha() { - repo=$1 - docker pull $1 &>/dev/null - sha=$(docker image inspect $1 | jq --raw-output '.[0].RootFS.Layers|.[]') # [0] means first element of list,[]means all the elments of lists - echo $sha -} - -is_base() { - local base_sha # alpine - local image_sha # new image - local base_repo=$1 - local image_repo=$2 - - base_sha=$(get_sha $base_repo) - image_sha=$(get_sha $image_repo) - - for i in $base_sha; do - local found="false" - for j in $image_sha; do - if [[ $i = $j ]]; then - found="true" - break - fi - done - if [ $found == "false" ]; then - echo "false" - return 0 - fi - done - echo "true" -} - -image_version() { - local version - repo=$1 # nginx repo - version=$(docker run -it $1 /bin/sh -c "nginx -v" |awk '{print$3}') - echo $version -} - -compare() { - result_arm=$(is_base $1 $2) - result_arm64=$(is_base $3 $4) - result_amd64=$(is_base $5 $6) - if [ $result_arm == "false" ] || [ $result_amd64 == "false" ] || [ $result_arm64 == "false" ]; - then - echo "true" - else - echo "false" - fi -} - -create_manifest() { - local repo=$1 - local tag1=$2 - local tag2=$3 - local x86=$4 - local rpi=$5 - local arm64=$6 - docker manifest create $repo:$tag1 $x86 $rpi $arm64 - docker manifest create $repo:$tag2 $x86 $rpi $arm64 - docker manifest annotate $repo:$tag1 $x86 --arch amd64 - docker manifest annotate $repo:$tag1 $rpi --arch arm - docker manifest annotate $repo:$tag1 $arm64 --arch arm64 - docker manifest annotate $repo:$tag2 $x86 --arch amd64 - docker manifest annotate $repo:$tag2 $rpi --arch arm - docker manifest annotate $repo:$tag2 $arm64 --arch arm64 -} - -build_image(){ - local repo=$1 # this is the base repo, for example treehouses/alpine - local arch=$2 #arm arm64 amd64 - local tag_repo=$3 # this is the tag repo, for example treehouses/node - if [ $# -le 1 ]; then - echo "missing parameters." - exit 1 - fi - sha=$(get_manifest_sha $@) - echo $sha - base_image="$repo@$sha" - echo $base_image - if [ -n "$sha" ]; then - tag=$tag_repo-tags:$arch - sed "s|{{base_image}}|$base_image|g" Dockerfile.template > Dockerfile.$arch - docker build -t $tag -f Dockerfile.$arch . - fi -} - -deploy_image(){ - local repo=$1 - local arch=$2 #arm arm64 amd64 - tag_arch=$repo-tags:$arch - tag_time=$(date +%Y%m%d%H%M) - tag_arch_time=$repo-tags:$arch-$tag_time - echo $tag_arch_time - docker tag $tag_arch $tag_arch_time - docker push $tag_arch_time - docker tag $tag_arch_time $tag_arch - docker push $tag_arch -} From 3ad8c9e26a3d1d43bce8953fd424f0f173bce67a Mon Sep 17 00:00:00 2001 From: Derek Yeh Date: Wed, 14 Jul 2021 18:18:12 -0700 Subject: [PATCH 2/6] Create turtleblocksjs.yml --- .github/workflows/turtleblocksjs.yml | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/turtleblocksjs.yml diff --git a/.github/workflows/turtleblocksjs.yml b/.github/workflows/turtleblocksjs.yml new file mode 100644 index 00000000..3c3543a1 --- /dev/null +++ b/.github/workflows/turtleblocksjs.yml @@ -0,0 +1,76 @@ +name: build on change + +on: + push: + branches: + - master + - main + - github-actions + workflow_dispatch: + repository_dispatch: + types: turtleblocksjs + +jobs: + turtleblocksjs: + runs-on: ubuntu-20.04 + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: docker login + run: docker login -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} + - name: treehouses turtleblocksjs + run: | + export DOCKER_CLI_EXPERIMENTAL=enabled + repo="treehouses/turtleblocksjs" + base="treehouses/nginx" + source .github/workflows/utils.sh + echo "amd64" + baseamd64=$(get_variant_sha "$base" "latest" "amd64") + echo $baseamd64 + repoamd64=$(get_manifest_sha "$repo:latest" "amd64") + echo $repoamd64 + echo "arm" + basearm=$(get_tag_sha "$base" "latest") + echo $basearm + repoarm=$(get_manifest_sha "$repo:latest" "arm") + echo $repoarm + echo "arm64" + basearm64=$(get_variant_sha "$base" "latest" "arm64") + echo $basearm64 + repoarm64=$(get_manifest_sha "$repo:latest" "arm64") + echo $repoarm64 + echo "change" + flag=$(compare_sha "$baseamd64" "$repoamd64" "$basearm" "$repoarm" "$basearm64" "$repoarm64") + echo $flag + if [[ $flag == true ]]; then + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + build_image "$base:latest" amd64 $repo + build_image "$base:latest" arm $repo + build_image "$base:latest" arm64 $repo + deploy_image $repo arm + deploy_image $repo amd64 + deploy_image $repo arm64 + sudo npm install -g @treehouses/cli + export gitter_channel="${{ secrets.CHANNEL }}" + echo "tags" + tag="$(date +%Y%m%d%H%M)" + echo $tag + docker manifest create $repo:$tag $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64 + docker manifest annotate $repo:$tag $repo-tags:amd64 --arch amd64 + docker manifest annotate $repo:$tag $repo-tags:arm64 --arch arm64 + docker manifest annotate $repo:$tag $repo-tags:arm --arch arm + docker manifest inspect $repo:$tag + docker manifest push $repo:$tag + tag2="latest" + echo $tag2 + docker manifest create $repo:$tag2 $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64 + docker manifest annotate $repo:$tag2 $repo-tags:amd64 --arch amd64 + docker manifest annotate $repo:$tag2 $repo-tags:arm64 --arch arm64 + docker manifest annotate $repo:$tag2 $repo-tags:arm --arch arm + docker manifest inspect $repo:$tag2 + docker manifest push $repo:$tag2 + echo "https://hub.docker.com/r/treehouses/turtleblocksjs/tags" + treehouses feedback "new treehouses/turtleblocksjs check https://hub.docker.com/r/treehouses/turtleblocksjs/tags" + else + echo "no changes" + fi From a7214cb5c7f59ee5deaf0506398e254061ce5c47 Mon Sep 17 00:00:00 2001 From: Derek Yeh Date: Wed, 14 Jul 2021 18:20:05 -0700 Subject: [PATCH 3/6] Create force.yml --- .github/workflows/force.yml | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/force.yml diff --git a/.github/workflows/force.yml b/.github/workflows/force.yml new file mode 100644 index 00000000..19c8c639 --- /dev/null +++ b/.github/workflows/force.yml @@ -0,0 +1,75 @@ +name: build by force + +on: +# push: +# branches: +# - master +# - main + workflow_dispatch: +# repository_dispatch: +# types: turtleblocksjs + +jobs: + turtleblocksjs: + runs-on: ubuntu-20.04 + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: docker login + run: docker login -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }} + - name: treehouses turtleblocksjs + run: | + export DOCKER_CLI_EXPERIMENTAL=enabled + repo="treehouses/turtleblocksjs" + base="treehouses/nginx" + source .github/workflows/utils.sh + echo "amd64" + baseamd64=$(get_variant_sha "$base" "latest" "amd64") + echo $baseamd64 + # repoamd64=$(get_manifest_sha "$repo:latest" "amd64") + # echo $repoamd64 + echo "arm" + basearm=$(get_tag_sha "$base" "latest") + echo $basearm + # repoarm=$(get_manifest_sha "$repo:latest" "arm") + # echo $repoarm + echo "arm64" + basearm64=$(get_variant_sha "$base" "latest" "arm64") + echo $basearm64 + # repoarm64=$(get_manifest_sha "$repo:latest" "arm64") + # echo $repoarm64 + echo "change" + flag=true #$(compare_sha "$baseamd64" "$repoamd64" "$basearm" "$repoarm" "$basearm64" "$repoarm64") + echo $flag + if [[ $flag == true ]]; then + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + build_image "$base:latest" amd64 $repo + build_image "$base:latest" arm $repo + build_image "$base:latest" arm64 $repo + deploy_image $repo arm + deploy_image $repo amd64 + deploy_image $repo arm64 + sudo npm install -g @treehouses/cli + export gitter_channel="${{ secrets.CHANNEL }}" + echo "tags" + tag="$(date +%Y%m%d%H%M)" + echo $tag + docker manifest create $repo:$tag $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64 + docker manifest annotate $repo:$tag $repo-tags:amd64 --arch amd64 + docker manifest annotate $repo:$tag $repo-tags:arm64 --arch arm64 + docker manifest annotate $repo:$tag $repo-tags:arm --arch arm + docker manifest inspect $repo:$tag + docker manifest push $repo:$tag + tag2="latest" + echo $tag2 + docker manifest create $repo:$tag2 $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64 + docker manifest annotate $repo:$tag2 $repo-tags:amd64 --arch amd64 + docker manifest annotate $repo:$tag2 $repo-tags:arm64 --arch arm64 + docker manifest annotate $repo:$tag2 $repo-tags:arm --arch arm + docker manifest inspect $repo:$tag2 + docker manifest push $repo:$tag2 + echo "https://hub.docker.com/r/treehouses/turtleblocksjs/tags" + treehouses feedback "new treehouses/turtleblocksjs check https://hub.docker.com/r/treehouses/turtleblocksjs/tags" + else + echo "no changes" + fi From 47ab79d1bf81730ad4ec8de76ee2d997b65a01cb Mon Sep 17 00:00:00 2001 From: Derek Yeh Date: Wed, 14 Jul 2021 18:22:22 -0700 Subject: [PATCH 4/6] Update turtleblocksjs.yml --- .github/workflows/turtleblocksjs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/turtleblocksjs.yml b/.github/workflows/turtleblocksjs.yml index 3c3543a1..3741efb3 100644 --- a/.github/workflows/turtleblocksjs.yml +++ b/.github/workflows/turtleblocksjs.yml @@ -21,8 +21,8 @@ jobs: - name: treehouses turtleblocksjs run: | export DOCKER_CLI_EXPERIMENTAL=enabled - repo="treehouses/turtleblocksjs" - base="treehouses/nginx" + repo="dyeh123/turtleblocksjs" + base="dyeh123/nginx" source .github/workflows/utils.sh echo "amd64" baseamd64=$(get_variant_sha "$base" "latest" "amd64") From 5f428ebd9de23f3fcd079fd457d498028c796596 Mon Sep 17 00:00:00 2001 From: Derek Yeh Date: Wed, 14 Jul 2021 18:32:59 -0700 Subject: [PATCH 5/6] Delete .travis.yml --- .travis.yml | 61 ----------------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index beb312ba..00000000 --- a/.travis.yml +++ /dev/null @@ -1,61 +0,0 @@ -sudo: required -addons: - apt: - update: true - packages: - - docker-ce -services: -- docker -script: -- export DOCKER_CLI_EXPERIMENTAL=enabled -- source utils.sh -- turtle_arm_sha=$(get_manifest_sha "treehouses/turtleblocksjs:latest" "arm") -- echo $turtle_arm_sha -- nginx_arm_sha=$(get_manifest_sha "treehouses/nginx:latest" "arm") -- echo $nginx_arm_sha -- flag_arm=$(is_base "treehouses/nginx@"$nginx_arm_sha "treehouses/turtleblocksjs@"$turtle_arm_sha) -- echo $flag_arm -- turtle_amd64_sha=$(get_manifest_sha "treehouses/turtleblocksjs:latest" "amd64") -- echo $turtle_amd64_sha -- nginx_amd64_sha=$(get_manifest_sha "treehouses/nginx:latest" "amd64") -- echo $nginx_amd64_sha -- flag_amd64=$(is_base "treehouses/nginx@"$nginx_amd64_sha "treehouses/turtleblocksjs@"$turtle_amd64_sha) -- echo $flag_amd64 -- turtle_arm64_sha=$(get_manifest_sha "treehouses/turtleblocksjs:latest" "arm64") -- echo $turtle_arm64_sha -- nginx_arm64_sha=$(get_manifest_sha "treehouses/nginx:latest" "arm64") -- echo $nginx_arm64_sha -- flag_arm64=$(is_base "treehouses/nginx@"$nginx_arm64_sha "treehouses/turtleblocksjs@"$turtle_arm64_sha) -- echo $flag_arm64 -- flag=$(compare "treehouses/nginx@"$nginx_arm_sha "treehouses/turtleblocksjs@"$turtle_arm_sha "treehouses/nginx@"$nginx_amd64_sha "treehouses/turtleblocksjs@"$turtle_amd64_sha "treehouses/nginx@"$nginx_arm64_sha "treehouses/turtleblocksjs@"$turtle_arm64_sha) -- echo $flag -before_deploy: -- echo "$DOCKERPASS" | docker login -u sevenseas --password-stdin -- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -- build_image "treehouses/nginx:latest" arm "treehouses/turtleblocksjs" #base image is arm arch -- build_image "treehouses/nginx:latest" amd64 "treehouses/turtleblocksjs" #base image is amd64 arch -- build_image "treehouses/nginx:latest" arm64 "treehouses/turtleblocksjs" #base image is arm64 arch -- deploy_image "treehouses/turtleblocksjs" arm -- deploy_image "treehouses/turtleblocksjs" amd64 -- deploy_image "treehouses/turtleblocksjs" arm64 -#before_deploy: #in case we want to check the code -- timetag=$(date +%Y%m%d%H%M) -- echo $timetag -- tag1="latest" -- tag2=$timetag -- echo "timetag is $tag2" -- create_manifest treehouses/turtleblocksjs $tag1 $tag2 treehouses/turtleblocksjs-tags:amd64 - treehouses/turtleblocksjs-tags:arm treehouses/turtleblocksjs-tags:arm64 -- docker manifest inspect treehouses/turtleblocksjs:$tag1 -- docker manifest inspect treehouses/turtleblocksjs:$tag2 -deploy: -- provider: script - script: docker manifest push treehouses/turtleblocksjs:$tag1; docker manifest push - treehouses/turtleblocksjs:$tag2 - skip_cleanup: true - on: - all_branches: true - condition: "$flag = true" -env: - global: - - secure: p/oMr9+Zmk991tu7JiNx1ySJ0LhzBFKHIGHJwhjSK0Cz0vhLv2Jw2ii9iW169mCFEut9LlGXwb8LeP54g/ZKfdj+RP+SsvrcUMyyZQaMQ12Fa0dC1hRu2+ovu+uffoH4IgoRt2Lc2YGi/Etr9QYLLdu6BD1Sx6KaSweEne1RCfXj2EyGsMqWWkE+N4xqhPsVICdjnmCXeg+ROVgOobtFjGn3BAujDsQBqpELWRAydGQNGgvYca8RQlLSnSTDNqrLEo4NyjyqKbvgAmp5UNDo6yA9MIQTUbbP7habpkrtAzR0+ilUAzsAc9x/6B0ua/eDaRVon5peIHnoM+kt5P5wNsZFt9spB1qsp/TL5Vif2wjvF9sMHO8baCOBI6yqc149Fmcpd6/JdQvyHt3vol8j9BcSG8y9Tr2GiceuwRTLWqgN6xHDFYsrOiSwddyY+BxK/Uqh50CZLKn/IQePfg/Hz+Qy1wRhiFiE9mYmcJ2BApc4hYT5LZ63KjeoJzoH6dP+p+AvXWeRAmYFvZiKtlPWJ9nEex+EhQ7d71icbBNxCmPcESoDgk6oHgA2qeThtXFUj8ApjuGsqNhJsXu6epHE+PnFB5+jllXNolo3sPDKB6cq1POzxb2AJDkzw56kxT3hzmyssBg0MqXZ46mpUOio233nEsuLpRAC8iIF+SeScKs= From 4eee6e7d78c59b5b48c4ad1f4f00e3b284b88659 Mon Sep 17 00:00:00 2001 From: Derek Yeh Date: Wed, 14 Jul 2021 18:40:06 -0700 Subject: [PATCH 6/6] Update turtleblocksjs.yml --- .github/workflows/turtleblocksjs.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/turtleblocksjs.yml b/.github/workflows/turtleblocksjs.yml index 3741efb3..a7769911 100644 --- a/.github/workflows/turtleblocksjs.yml +++ b/.github/workflows/turtleblocksjs.yml @@ -5,7 +5,6 @@ on: branches: - master - main - - github-actions workflow_dispatch: repository_dispatch: types: turtleblocksjs @@ -21,8 +20,8 @@ jobs: - name: treehouses turtleblocksjs run: | export DOCKER_CLI_EXPERIMENTAL=enabled - repo="dyeh123/turtleblocksjs" - base="dyeh123/nginx" + repo="treehouses/turtleblocksjs" + base="treehouses/nginx" source .github/workflows/utils.sh echo "amd64" baseamd64=$(get_variant_sha "$base" "latest" "amd64")