Skip to content

Commit

Permalink
github actions workflow (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
rjpadilla and dogi authored Aug 26, 2021
1 parent 59e1a2a commit a0b125e
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 274 deletions.
78 changes: 0 additions & 78 deletions .github/workflows/force.yml

This file was deleted.

177 changes: 111 additions & 66 deletions .github/workflows/pm2.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,123 @@
name: build on change
name: build image

on:
on:
push:
branches:
- master
- main
workflow_dispatch:
repository_dispatch:
types: pm2
workflow_dispatch:
inputs:
buildtype:
description: 'Build by "force" or on "change"'
required: true
default: 'force'
repository_dispatch:
types: pm2

jobs:
pm2:
runs-on: ubuntu-20.04

compare:
runs-on: ubuntu-latest
outputs:
flag: ${{ steps.set-flag.outputs.flag }}
strategy:
fail-fast: false
matrix:
arch: [amd64, arm, arm64]
steps:
- name: checkout repository
uses: actions/checkout@v2
- name: container registries
run: |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }}
- name: compare image
id: set-flag
run: |
export DOCKER_CLI_EXPERIMENTAL=enabled
repo="treehouses/pm2-tags:${{ matrix.arch }}"
base="treehouses/node-tags:${{ matrix.arch }}"
docker pull -q $base &>/dev/null
docker pull -q $repo &>/dev/null
basesha=$(docker image inspect $base | jq --raw-output '.[0].RootFS.Layers|.[]')
reposha=$(docker image inspect $repo | jq --raw-output '.[0].RootFS.Layers|.[]')
echo "base sha:$basesha repo sha:$reposha"
${{ github.event.inputs.buildtype == 'force' }} && echo "::set-output name=flag::true" || echo "building on change"
[[ $reposha == *$basesha* ]] && echo "no changes" || echo "::set-output name=flag::true"
images:
needs: compare
runs-on: ubuntu-latest
outputs:
build: ${{ steps.set-build.outputs.build }}
strategy:
fail-fast: false
matrix:
arch: [amd64, arm, arm64]
steps:
- name: Checkout
- name: checkout repository
uses: actions/checkout@v2
- name: login to docker
run: docker login -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }}
- name: treehouses pm2
- name: container registries
run: |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }}
- name: docker image
if: ${{ needs.compare.outputs.flag }}
id: set-build
run: |
export DOCKER_CLI_EXPERIMENTAL=enabled
repo="treehouses/pm2"
base="treehouses/node"
source .github/workflows/utils.sh
echo "amd64"
baseamd64=$(get_manifest_sha "$base:latest" "amd64")
echo $baseamd64
repoamd64=$(get_manifest_sha "$repo:latest" "amd64")
echo $repoamd64
echo "flag amd64"
flag_amd64=$(is_base "$base@"$baseamd64 "$repo@"$repoamd64)
echo $flag_amd64
echo "arm"
basearm=$(get_manifest_sha "$base:latest" "arm")
echo $basearm
repoarm=$(get_manifest_sha "$repo:latest" "arm")
echo $repoarm
flagarm=$(is_base "$base@"$basearm "$repo@"$repoarm)
echo "flag arm"
echo $flagarm
echo "arm64"
basearm64=$(get_manifest_sha "$base:latest" "arm64")
echo $basearm64
repoarm64=$(get_manifest_sha "$repo:latest" "arm64")
echo $repoarm64
echo "flag arm64"
flagarm64=$(is_base "$base@"$basearm64 "$repo@"$repoarm64)
echo $flagarm64
version2=$(image_version $repo:latest)
echo "repo version is $version2"
flag=$(compare "$base@"$basearm "$repo@"$repoarm "$base@"$baseamd64 "$repo@"$repoamd64 "$base@"$basearm64 "$repo@"$repoarm64 "$repo" "$repo-tags:amd64")
echo $flag
if [[ $flag == true ]]; then
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
build_image "$base:latest" arm "$repo"
build_image "$base:latest" amd64 "$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)
tag2="latest"
echo $tag
create_manifest $repo $tag $tag2 $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64
docker manifest inspect $repo:$tag
docker manifest inspect $repo:$tag2
docker manifest push $repo:$tag; docker manifest push $repo:$tag2
echo "https://hub.docker.com/r/treehouses/pm2/tags"
treehouses feedback "new treehouses/pm2 check https://hub.docker.com/r/treehouses/pm2/tags"
else
echo "no changes"
fi
base="treehouses/node-tags:${{ matrix.arch }}"
repo="treehouses/pm2-tags"
dest="$repo:${{ matrix.arch }}"
date="$(date +%Y%m%d%H%M)"
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker build -t ghcr.io/$dest --build-arg BASE=$base .
docker tag ghcr.io/$dest docker.io/$dest
docker tag ghcr.io/$dest ghcr.io/$dest-$date
docker tag docker.io/$dest docker.io/$dest-$date
docker push --all-tags ghcr.io/$repo
docker push --all-tags docker.io/$repo
docker images
echo "::set-output name=build::true"
manifests:
needs: images
strategy:
fail-fast: false
matrix:
registry: [docker.io, ghcr.io]
runs-on: ubuntu-latest
outputs:
send: ${{ steps.set-send.outputs.send }}
steps:
- name: container registries
run: |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }}
- name: create manifests
if: ${{ needs.images.outputs.build }}
id: set-send
run: |
repo="${{ matrix.registry }}/treehouses/pm2"
date="$(date +%Y%m%d%H%M)"
docker manifest create $repo:latest $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64
docker manifest create $repo:$date $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64
docker manifest annotate $repo:latest $repo-tags:arm --os linux --arch arm
docker manifest annotate $repo:$date $repo-tags:arm --os linux --arch arm
docker manifest inspect $repo:latest
docker manifest push $repo:latest
docker manifest push $repo:$date
echo "::set-output name=send::true"
message:
needs: manifests
runs-on: ubuntu-latest
steps:
- name: message chat of new image
if: ${{ needs.manifests.outputs.send }}
run: |
sudo npm install -g @treehouses/cli
export gitter_channel="${{ secrets.CHANNEL }}"
echo "https://hub.docker.com/r/treehouses/pm2/tags"
echo "https://github.com/treehouses/pm2/pkgs/container/pm2"
treehouses feedback "new treehouses/pm2 check https://hub.docker.com/r/treehouses/pm2/tags or https://github.com/treehouses/pm2/pkgs/container/pm2"
121 changes: 0 additions & 121 deletions .github/workflows/utils.sh

This file was deleted.

Loading

0 comments on commit a0b125e

Please sign in to comment.