Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate from travis to github actions #12

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/force.yml
Original file line number Diff line number Diff line change
@@ -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
75 changes: 75 additions & 0 deletions .github/workflows/turtleblocksjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: build on change

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=$(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
112 changes: 112 additions & 0 deletions .github/workflows/utils.sh
Original file line number Diff line number Diff line change
@@ -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
}
61 changes: 0 additions & 61 deletions .travis.yml

This file was deleted.

Loading