-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new workflows to build docker images
- Loading branch information
1 parent
9547160
commit 7ab6d21
Showing
2 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
.github/workflows/build-bothub-engine-dispatch-dockerhub.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
name: Build Bothub Engine (Dispatch) | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
|
||
source-branch: | ||
description: 'Source branch in repository (master, staging, develop, fix/sentry etc.)' | ||
required: true | ||
default: 'master' | ||
|
||
tag-name: | ||
description: 'Tag id (v0.0.1-develop, v0.0.2, etc.)' | ||
required: true | ||
|
||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{github.event.inputs.source-branch}} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
# - name: Login to ECR | ||
# uses: docker/login-action@v1 | ||
# with: | ||
# registry: 869898323958.dkr.ecr.us-east-1.amazonaws.com | ||
# username: ${{ secrets.AWS_ACCESS_KEY_ID_SHARED }} | ||
# password: ${{ secrets.AWS_SECRET_ACCESS_KEY_SHARED }} | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push - Bothub WebApp Image | ||
id: docker_build1 | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
labels: branch=${{github.event.inputs.source-branch}},commit=${{env.GITHUB_SHA}},repository=https://github.com/Ilhasoft/bothub-engine | ||
file: Dockerfile | ||
push: true | ||
tags: bothubit/bothub-engine:${{github.event.inputs.tag-name}} | ||
no-cache: true | ||
|
||
- name: Check out Kubernetes Manifests | ||
uses: actions/checkout@master | ||
with: | ||
ref: main | ||
repository: Ilhasoft/kubernetes-manifests-artificial-intelligence | ||
token: ${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }} | ||
path: ./kubernetes-manifests/ | ||
|
||
- name: Set variable tag for jq | ||
run: | | ||
echo "IMAGE_TAG=bithubit/bothub-engine:${{github.event.inputs.tag-name}}" >> $GITHUB_ENV | ||
- name: Update image on deployment | ||
run: | | ||
which jq > /dev/null 2>&1 || ( sudo apt update ; sudo apt install -y jq ) | ||
# Dep: coreutils | ||
verlte() { | ||
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | ||
} | ||
verlt(){ | ||
[ "$1" = "$2" ] && return 1 || verlte $1 $2 | ||
} | ||
export PROJECT_DIR="inteligencia-artificial" PATCH_TARGET="deployment-engine.json" | ||
ENV_DIR=$( | ||
find kubernetes-manifests/${PROJECT_DIR}/ -maxdepth 1 -mindepth 1 -type d \ | ||
| egrep -v -e '.git' -e '/base$' \ | ||
| while read dirname ; do | ||
test -r "${dirname}/kustomization.yaml" && echo "${dirname}" | ||
done | ||
) | ||
for e in ${ENV_DIR}; do | ||
echo "Update ${e}:" | ||
if [ ! -d "kubernetes-manifests/${PROJECT_DIR}/${e}" ] ; then | ||
echo "kubernetes-manifests/${PROJECT_DIR}/${e}: Does not exist, skipping" | ||
elif [ ! -r "kubernetes-manifests/${PROJECT_DIR}/${e}/kustomization.yaml" ] ; then | ||
echo "kubernetes-manifests/${PROJECT_DIR}/${e}/kustomization.yaml: Does not readable, skipping" | ||
elif [ ! -r "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" ] ; then | ||
echo "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}: Does not readable, skipping" | ||
else | ||
OLD_IMAGE=$( | ||
cat "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" \ | ||
| jq '.[] | select(.path == "/spec/template/spec/containers/0/image") | .value' | ||
) | ||
echo "Old image to replace: ${OLD_IMAGE}" | ||
OLD_VERSION=$( | ||
echo "${OLD_IMAGE}" \ | ||
| sed s'/^.*[v:-]\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'g \ | ||
| head -n1 | ||
) | ||
NEW_VERSION=$(echo ${{github.event.inputs.tag-name}}|grep -o -e '[0-9]*\.[0-9]*\.[0-9]*') | ||
echo "Old image version to compare: ${OLD_VERSION}<=${NEW_VERSION}" | ||
if verlte "${OLD_VERSION}" "${NEW_VERSION}" ; then | ||
echo 'New configurations:' | ||
new_configuration=$( | ||
cat "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" \ | ||
| jq '(..|select(.path == "/spec/template/spec/containers/0/image")?) += {value: "'"${{env.IMAGE_TAG}}"'"}' | ||
) | ||
echo "${new_configuration}" | ||
echo "${new_configuration}" > "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" | ||
else | ||
echo "Version in file is greater than build, skiping update yaml" | ||
fi | ||
fi | ||
done | ||
- name: Commit & Push changes | ||
uses: actions-js/push@master | ||
with: | ||
github_token: ${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }} | ||
repository: Ilhasoft/kubernetes-manifests-artificial-intelligence | ||
directory: ./kubernetes-manifests/ | ||
branch: main | ||
message: "From Bothub Engine Build (Dispatch)" | ||
|
||
- name: Generated Image URL to Copy | ||
run: | | ||
echo ${{ env.IMAGE_TAG }} |
172 changes: 172 additions & 0 deletions
172
.github/workflows/build-bothub-engine-push-tag-dockerhub.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
name: Build Bothub Engine (Push Tag) | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*-develop*' | ||
- 'v*.*.*-staging*' | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set variables | ||
run: | | ||
TAG=$(echo $GITHUB_REF|cut -d"/" -f3) | ||
if $(echo $TAG|grep --silent -e 'v*.*.*-develop*') | ||
then | ||
echo "Found environment: DEVELOP - $TAG" | ||
echo "MANIFESTS_ENVIRONMENT=develop" >> $GITHUB_ENV | ||
echo "MANIFESTS_ENVIRONMENT=develop" | ||
echo "TAG=$TAG" >> $GITHUB_ENV | ||
echo "TAG=$TAG" | ||
VERSION=${TAG#v} | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
echo "VERSION=$VERSION" | ||
echo "COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV | ||
echo "COMMIT_SHA=$GITHUB_SHA" | ||
echo "IMAGE_TAG=bothubit/bothub-engine:$TAG" >> $GITHUB_ENV | ||
echo "IMAGE_TAG=bothubit/bothub-engine:$TAG" | ||
elif $(echo $TAG|grep --silent -e 'v*.*.*-staging*') | ||
then | ||
echo "Found environment: STAGING - $TAG" | ||
echo "MANIFESTS_ENVIRONMENT=staging" >> $GITHUB_ENV | ||
echo "MANIFESTS_ENVIRONMENT=staging" | ||
echo "TAG=$TAG" >> $GITHUB_ENV | ||
echo "TAG=$TAG" | ||
VERSION=${TAG#v} | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
echo "VERSION=$VERSION" | ||
echo "COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV | ||
echo "COMMIT_SHA=$GITHUB_SHA" | ||
echo "IMAGE_TAG=bothubit/bothub-engine:$TAG" >> $GITHUB_ENV | ||
echo "IMAGE_TAG=bothubit/bothub-engine:$TAG" | ||
elif $(echo $TAG|grep --silent -e 'v*.*.*') | ||
then | ||
echo "No environment found, assuming: PRODUCTION - $TAG" | ||
echo "MANIFESTS_ENVIRONMENT=production" >> $GITHUB_ENV | ||
echo "MANIFESTS_ENVIRONMENT=production" | ||
echo "TAG=$TAG" >> $GITHUB_ENV | ||
echo "TAG=$TAG" | ||
VERSION=${TAG#v} | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
echo "VERSION=$VERSION" | ||
echo "COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV | ||
echo "COMMIT_SHA=$GITHUB_SHA" | ||
echo "IMAGE_TAG=bothubit/bothub-engine:$TAG" >> $GITHUB_ENV | ||
echo "IMAGE_TAG=bothubit/bothub-engine:$TAG" | ||
else | ||
echo 'Not a valid tag. Skipping...' | ||
exit 1 | ||
fi | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{env.GITHUB_SHA}} | ||
repository: Ilhasoft/bothub-engine | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
# - name: Login to ECR | ||
# uses: docker/login-action@v1 | ||
# with: | ||
# registry: 869898323958.dkr.ecr.us-east-1.amazonaws.com | ||
# username: ${{secrets.AWS_ACCESS_KEY_ID_SHARED}} | ||
# password: ${{secrets.AWS_SECRET_ACCESS_KEY_SHARED}} | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push - Bothub Engine Image | ||
id: docker_build1 | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
labels: branch=${{env.TAG}},commit=${{env.COMMIT_SHA}},repository=https://github.com/Ilhasoft/bothub-engine | ||
file: Dockerfile | ||
push: true | ||
tags: ${{env.IMAGE_TAG}} | ||
no-cache: true | ||
|
||
- name: Check out Kubernetes Manifests | ||
uses: actions/checkout@master | ||
with: | ||
ref: main | ||
repository: Ilhasoft/kubernetes-manifests-artificial-intelligence | ||
token: ${{secrets.DEVOPS_GITHUB_PERMANENT_TOKEN}} | ||
path: ./kubernetes-manifests/ | ||
|
||
- name: Update image on deployment | ||
run: | | ||
which jq > /dev/null 2>&1 || ( sudo apt update ; sudo apt install -y jq ) | ||
# Dep: coreutils | ||
verlte() { | ||
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | ||
} | ||
verlt(){ | ||
[ "$1" = "$2" ] && return 1 || verlte $1 $2 | ||
} | ||
export PROJECT_DIR="inteligencia-artificial" PATCH_TARGET="deployment-engine.json" | ||
ENV_DIR=$( | ||
find kubernetes-manifests/${PROJECT_DIR}/ -maxdepth 1 -mindepth 1 -type d \ | ||
| egrep -v -e '.git' -e '/base$' \ | ||
| while read dirname ; do | ||
test -r "${dirname}/kustomization.yaml" && echo "${dirname}" | ||
done | ||
) | ||
for e in ${ENV_DIR}; do | ||
echo "Update ${e}:" | ||
if [ ! -d "kubernetes-manifests/${PROJECT_DIR}/${e}" ] ; then | ||
echo "kubernetes-manifests/${PROJECT_DIR}/${e}: Does not exist, skipping" | ||
elif [ ! -r "kubernetes-manifests/${PROJECT_DIR}/${e}/kustomization.yaml" ] ; then | ||
echo "kubernetes-manifests/${PROJECT_DIR}/${e}/kustomization.yaml: Does not readable, skipping" | ||
elif [ ! -r "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" ] ; then | ||
echo "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}: Does not readable, skipping" | ||
else | ||
OLD_IMAGE=$( | ||
cat "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" \ | ||
| jq '.[] | select(.path == "/spec/template/spec/containers/0/image") | .value' | ||
) | ||
echo "Old image to replace: ${OLD_IMAGE}" | ||
OLD_VERSION=$( | ||
echo "${OLD_IMAGE}" \ | ||
| sed s'/^.*[v:-]\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'g \ | ||
| head -n1 | ||
) | ||
echo "Old image version to compare: ${OLD_VERSION}<=${{env.VERSION}}" | ||
if verlte "${OLD_VERSION}" "${{env.VERSION}}" ; then | ||
echo 'New configurations:' | ||
new_configuration=$( | ||
cat "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" \ | ||
| jq '(..|select(.path == "/spec/template/spec/containers/0/image")?) += {value: "'"${{env.IMAGE_TAG}}"'"}' | ||
) | ||
echo "${new_configuration}" | ||
echo "${new_configuration}" > "kubernetes-manifests/${PROJECT_DIR}/${e}/${PATCH_TARGET}" | ||
else | ||
echo "Version in file is greater than build, skiping update yaml" | ||
fi | ||
fi | ||
done | ||
- name: Commit & Push changes | ||
uses: actions-js/push@master | ||
with: | ||
github_token: ${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }} | ||
repository: Ilhasoft/kubernetes-manifests-artificial-intelligence | ||
directory: ./kubernetes-manifests/ | ||
branch: main | ||
message: "From Bothub Engine Build (Push-Tag)" | ||
|
||
- name: Generated Image | ||
run: | | ||
echo "IMAGE: " ${{env.IMAGE_TAG}} |