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

github action (fixes #25) #27

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
6369f9d
changed
Nov 23, 2020
ec37046
updated
Nov 23, 2020
99e73fc
updated
Nov 23, 2020
55f4853
updated
Nov 23, 2020
49e22d6
Update Dockerfile.template
Neethu-Mohan Nov 23, 2020
e6ee25c
Update Dockerfile.template
Neethu-Mohan Nov 23, 2020
8d78c28
Update .travis.yml
Neethu-Mohan Nov 23, 2020
b12a0fa
Update .travis.yml
Neethu-Mohan Nov 23, 2020
eda7c81
Update Dockerfile.template
Neethu-Mohan Nov 25, 2020
c92194e
Update Dockerfile.template
Neethu-Mohan Nov 25, 2020
f3ba2d2
Update Dockerfile.template
Neethu-Mohan Nov 26, 2020
677b3c5
Update .travis.yml
Neethu-Mohan Nov 26, 2020
63fc404
Update Dockerfile.template
Neethu-Mohan Nov 26, 2020
abeb5a3
Update Dockerfile.template
Neethu-Mohan Nov 26, 2020
56f2934
updated
Nov 27, 2020
14bed2d
Update utils.sh
Neethu-Mohan Nov 27, 2020
044046c
Create kolibri.yml
Neethu-Mohan Apr 24, 2021
b810001
version1
Apr 24, 2021
7833f1c
Update kolibri.yml
Neethu-Mohan Apr 24, 2021
da8eb6c
version2
Apr 24, 2021
a116abf
version2
Apr 24, 2021
e33a295
version3
Apr 24, 2021
e3a1429
Update kolibri.yml
Neethu-Mohan Apr 24, 2021
a8758a0
version3
Apr 24, 2021
fb884f8
version4
Apr 24, 2021
7329f35
Update kolibri.yml
Neethu-Mohan Apr 24, 2021
13e4c49
Update kolibri.yml
Neethu-Mohan Apr 24, 2021
b2be3e9
version5
Apr 24, 2021
eaad305
Merge branch 'master' of https://github.com/Neethu-Mohan/kolibri
Apr 24, 2021
effea95
version7
Apr 24, 2021
2b5c4b1
test1
Apr 30, 2021
6ef8166
test2
Apr 30, 2021
25f7439
test3
Apr 30, 2021
16de74b
test4
Apr 30, 2021
56419b8
test5
May 1, 2021
aaf88a5
test6
May 1, 2021
55deef4
test7
May 1, 2021
82596dc
test8
May 1, 2021
b280cda
test9
May 1, 2021
1e11dbd
test9
May 1, 2021
db733a2
test10
May 1, 2021
7de1879
test1
May 1, 2021
2c5879a
teat2
May 1, 2021
76e4d1c
test3
May 1, 2021
12a67d9
test4
May 1, 2021
fc139fc
test
May 1, 2021
cb2bbc6
test
May 1, 2021
958e58c
test
May 1, 2021
ac7be36
test
May 1, 2021
6d35c91
test
May 1, 2021
3b05850
final test
May 1, 2021
0b25e05
final test
May 1, 2021
bed12cc
final test
May 1, 2021
e2f5381
final test
May 1, 2021
e37626b
final test
May 1, 2021
c1abe8d
final test
May 1, 2021
4b8d201
changes updated
May 1, 2021
81019f3
Update .travis.yml
Neethu-Mohan May 1, 2021
f227e8f
Rename .travis.yml to .travis.yml.old
dogi May 1, 2021
1e1fedd
Rename utils.sh to .github/workflow/utils.sh
dogi May 1, 2021
fdcc18b
Rename .github/workflow/utils.sh to .github/workflows/utils.sh
dogi May 1, 2021
58b5b5c
Update kolibri.yml
dogi May 1, 2021
a63e86b
Update kolibri.yml
dogi May 1, 2021
87c6aba
Update kolibri.yml
dogi May 1, 2021
581468c
changes
May 1, 2021
407bd95
changes
May 1, 2021
17cf43c
Update kolibri.yml
Neethu-Mohan May 1, 2021
c29149c
updated
May 1, 2021
8fa1902
updated
May 1, 2021
54149af
updated
May 1, 2021
a15a368
Update kolibri.yml
Neethu-Mohan May 20, 2021
33455e9
Update kolibri.yml
Neethu-Mohan May 20, 2021
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
59 changes: 59 additions & 0 deletions .github/workflows/kolibri.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: kolibri-docker-image-build

on:
push:
workflow_dispatch:
repository_dispatch:
types: kolibri

jobs:
kolibri:
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: neethumohan1212 kolibri
run: |
export DOCKER_CLI_EXPERIMENTAL=enabled
repo="neethumohan1212/kolibri"
source .github/workflows/utils.sh
alpine_arm_sha=$(get_manifest_sha "treehouses/alpine:latest" "arm")
echo $alpine_arm_sha
kolibri_arm_sha=$(get_manifest_sha $repo:latest arm)
echo $kolibri_arm_sha
flag_arm=$(is_base "treehouses/alpine@"$alpine_arm_sha "$repo@"$kolibri_arm_sha)
echo $flag_arm
alpine_amd64_sha=$(get_manifest_sha "treehouses/alpine:latest" "amd64")
echo $alpine_amd64_sha
kolibri_amd64_sha=$(get_manifest_sha "$repo:latest" "amd64")
echo $kolibri_amd64_sha
flag_amd64=$(is_base "treehouses/alpine@"$alpine_amd64_sha "neethumohan1212/kolibri@"$kolibri_amd64_sha)
echo $flag_amd64
alpine_arm64_sha=$(get_manifest_sha "treehouses/alpine:latest" "arm64")
echo $alpine_arm64_sha
kolibri_arm64_sha=$(get_manifest_sha "$repo:latest" "arm64")
echo $kolibri_arm64_sha
flag_arm64=$(is_base "treehouses/alpine@"$alpine_arm64_sha "$repo@"$kolibri_arm64_sha)
echo $flag_arm64
flag=$(change $flag_arm $flag_arm64 $flag_amd64)
#flag="true"
echo $flag
if [[ $flag == true ]]; then
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
build_image "treehouses/alpine:latest" arm "$repo" $flag_arm
build_image "treehouses/alpine:latest" amd64 "$repo" $flag_amd64
build_image "treehouses/alpine:latest" arm64 "$repo" $flag_arm64
tag1="latest"
tag2="$(date +%Y%m%d%H%M)"
echo $tag2
docker manifest create $repo:$tag1 $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64
docker manifest create $repo:$tag2 $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64
docker manifest inspect $repo:$tag1
docker manifest inspect $repo:$tag2
docker manifest push $repo:$tag1; docker manifest push $repo:$tag2
else
echo "no changes"
fi

116 changes: 116 additions & 0 deletions .github/workflows/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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
}

change() {
flag_arm=$1
flag_arm64=$2
flag_amd64=$3
if [ $flag_arm == "false" ] || [ $flag_arm64 == "false" ] || [ $flag_amd64 == "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
}
54 changes: 0 additions & 54 deletions .travis.yml

This file was deleted.

59 changes: 59 additions & 0 deletions .travis.yml.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
sudo: required
addons:
apt:
update: true
packages:
- docker-ce
services:
- docker
script:
- export DOCKER_CLI_EXPERIMENTAL=enabled
- source utils.sh
- alpine_arm_sha=$(get_manifest_sha "treehouses/alpine:latest" "arm")
- echo $alpine_arm_sha
- kolibri_arm_sha=$(get_manifest_sha "treehouses/kolibri:latest" "arm")
- echo $kolibri_arm_sha
- flag_arm=$(is_base "treehouses/alpine@"$alpine_arm_sha "treehouses/kolibri@"$kolibri_arm_sha)
- echo $flag_arm
- alpine_amd64_sha=$(get_manifest_sha "treehouses/alpine:latest" "amd64")
- echo $alpine_amd64_sha
- kolibri_amd64_sha=$(get_manifest_sha "treehouses/kolibri:latest" "amd64")
- echo $kolibri_amd64_sha
- flag_amd64=$(is_base "treehouses/alpine@"$alpine_amd64_sha "treehouses/kolibri@"$kolibri_amd64_sha)
- echo $flag_amd64
- alpine_arm64_sha=$(get_manifest_sha "treehouses/alpine:latest" "arm64")
- echo $alpine_arm64_sha
- kolibri_arm64_sha=$(get_manifest_sha "treehouses/kolibri:latest" "arm64")
- echo $kolibri_arm64_sha
- flag_arm64=$(is_base "treehouses/alpine@"$alpine_arm64_sha "treehouses/kolibri@"$kolibri_arm64_sha)
- echo $flag_arm64
- echo $DOCKERAPIKEY | docker login -u "treehouses" --password-stdin
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- build_image "treehouses/alpine:latest" arm "treehouses/kolibri" $flag_arm
- build_image "treehouses/alpine:latest" amd64 "treehouses/kolibri" $flag_amd64
- build_image "treehouses/alpine:latest" arm64 "treehouses/kolibri" $flag_arm64
- flag=$(change $flag_arm $flag_arm64 $flag_amd64)
- flag="true"
- echo $flag
before_deploy:
- deploy_image "treehouses/kolibri" arm
- deploy_image "treehouses/kolibri" amd64
- deploy_image "treehouses/kolibri" arm64
- tag1="latest"
- tag2=$(date +%Y%m%d%H%M)
- echo $tag2
- create_manifest treehouses/kolibri $tag1 $tag2 treehouses/kolibri-tags:amd64
treehouses/kolibri-tags:arm treehouses/kolibri-tags:arm64
- docker manifest inspect treehouses/kolibri:$tag1
- docker manifest inspect treehouses/kolibri:$tag2
deploy:
- provider: script
script: docker manifest push treehouses/kolibri:$tag1; docker manifest push
treehouses/kolibri:$tag2
skip_cleanup: true
on:
all_branches: true
condition: "$flag = true"
env:
global:
- secure: QYa0ylNHvZQovle8c4+cR4i23tZ6NUaf/iYepLpuxKt3fRTvLRdDQs0tPgfTUVQtkQqYaNM/J6n+LaML+Wc5blBiKafUd8wDYUIfIKwguYBwNFZwYEy2WfaVSj4sNgPXaOc4iu7Im5pi6eeXmjSINuG2/eOVVQEtz6ST/WvIbA6Jr4oZ68P6b8H2VJxMd2RTAVG6BH+2BaeBy/l/hAGAk97mo1Ji1UIXPnC3pTM1ZDDEHPog24j0OziAkKOdKdBY9FXWeWKTISZOGcjVW8PN6RRMuENGw6+yPNhk7A8IQTvk1B23gvtCH81N8M5Igu7MfFZHg2+mHkvYVwHeVvQXJdBNUq4Bv0wQn66Buqo8+Je9jGtWyUZzy7xyFQA47BWfwKGqqTAqTOdlYruaak7UqhwQLMeX5terKy5nfgw4gJ8JYqk5KL3HnTym4yNXc2DhZgVOWuh5sqET+JN2+xA72QjWyIkP/RCIzZDHbPYqQjLlKwqdviYJFdJeeRpPnKDS1eeRojd0WL3y42ACdFDxndN2LQ2umQL+HOtomZB+gVRjrbuSbyecbDEVxRjifQYzJthRtmzCUReUmZE9FB9xxRjV/0+Enfr2tZJmXn+C1reTDZp+kvy9pdbWcBW9FDRGLHCubeloHKT05b7PpyM0RRfNGQIgpDTcAxMT1FbfnjI=
Loading