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

Change Github token used in secret, remove old builds #55

Open
wants to merge 16 commits into
base: main
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
39 changes: 39 additions & 0 deletions .github/workflows/build-develop-india-mailroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# name: Build Develop India Mailroom
# on:
# push:
# tags:
# - 'v*.*.*-develop*'
# jobs:
# docker:
# runs-on: ubuntu-latest
# environment:
# name: develop-india
# steps:
# - name: Set output
# id: vars
# run: |
# echo ::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/}|cut -d'-' -f3-4|tr -s '-' '/');
# echo ::set-output name=tag::$(echo ${GITHUB_REF#refs/heads/}|cut -d'/' -f3-|cut -d'-' -f1-2);
# - name: Check out the repo
# uses: actions/checkout@v2
# with:
# ref: ${{ steps.vars.ouptuts.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: 242357350604.dkr.ecr.ap-south-1.amazonaws.com
# username: ${{ secrets.AWS_ACCESS_KEY_ID }}
# password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# - name: Build and push - Mailroom Image
# id: docker_build1
# uses: docker/build-push-action@v2
# with:
# context: .
# file: docker/Dockerfile
# push: true
# tags: 242357350604.dkr.ecr.ap-south-1.amazonaws.com/mailroom:${{ steps.vars.outputs.tag }}
# no-cache: true
43 changes: 43 additions & 0 deletions .github/workflows/build-develop-ireland-mailroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# name: Build Develop Ireland Mailroom
# on:
# push:
# tags:
# - 'v*.*.*-develop*'
# jobs:
# docker:
# runs-on: ubuntu-latest
# environment:
# name: develop-ireland
# steps:
# - name: Set output
# id: vars
# run: |
# echo ::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/}|cut -d'-' -f3-4|tr -s '-' '/');
# echo ::set-output name=tag::$(echo ${GITHUB_REF#refs/heads/}|cut -d'/' -f3-|cut -d'-' -f1-2);
# - name: Check out the repo
# uses: actions/checkout@v2
# with:
# ref: ${{ steps.vars.ouptuts.branch }}
# - name: Check out the repo
# uses: actions/checkout@v2
# with:
# ref: feature/build
# - 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: 452158872079.dkr.ecr.eu-west-1.amazonaws.com
# username: ${{ secrets.AWS_ACCESS_KEY_ID }}
# password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# - name: Build and push - Mailroom Image
# id: docker_build1
# uses: docker/build-push-action@v2
# with:
# context: .
# file: docker/Dockerfile
# push: true
# tags: 452158872079.dkr.ecr.eu-west-1.amazonaws.com/rp-mailroom-rapidpro:${{ steps.vars.outputs.tag }}
# no-cache: true
43 changes: 43 additions & 0 deletions .github/workflows/build-develop-sp-mailroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# name: Build Develop SP Mailroom
# on:
# push:
# tags:
# - 'v*.*.*-develop*'
# jobs:
# docker:
# runs-on: ubuntu-latest
# environment:
# name: develop
# steps:
# - name: Set output
# id: vars
# run: |
# echo ::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/}|cut -d'-' -f3-4|tr -s '-' '/');
# echo ::set-output name=tag::$(echo ${GITHUB_REF#refs/heads/}|cut -d'/' -f3-|cut -d'-' -f1-2);
# - name: Check out the repo
# uses: actions/checkout@v2
# with:
# ref: ${{ steps.vars.ouptuts.branch }}
# - name: Check out the repo
# uses: actions/checkout@v2
# with:
# ref: feature/build
# - 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: 242357350604.dkr.ecr.sa-east-1.amazonaws.com
# username: ${{ secrets.AWS_ACCESS_KEY_ID }}
# password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# - name: Build and push - Mailroom Image
# id: docker_build1
# uses: docker/build-push-action@v2
# with:
# context: .
# file: docker/Dockerfile
# push: true
# tags: 242357350604.dkr.ecr.sa-east-1.amazonaws.com/push-mailroom:${{ steps.vars.outputs.tag }}
# no-cache: true
123 changes: 123 additions & 0 deletions .github/workflows/build-mailroom-dispatch-shared.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Build Rapidpro Mailroom in Shared (Dispatch)

on:
workflow_dispatch:
inputs:

source-branch:
description: 'Source branch in Mailroom repository (main, staging, develop, fix/sentry etc.)'
required: true
default: 'main'

tag-name:
description: 'Tag id (v0.0.1-develop, v0.0.2, etc.)'
required: true

destination-env:
description: 'Destination environment (develop, production, staging)'
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: Build and push - Mailroom 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/mailroom
file: ./docker/Dockerfile
push: true
tags: 869898323958.dkr.ecr.us-east-1.amazonaws.com/mailroom:${{github.event.inputs.tag-name}}
no-cache: true

- name: Check out Kubernetes Manifests
uses: actions/checkout@master
with:
ref: main
repository: Ilhasoft/kubernetes-manifests-platform
token: ${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }}
path: ./kubernetes-manifests/

- name: Set variable tag for jq
run: |
echo "IMAGE_TAG=869898323958.dkr.ecr.us-east-1.amazonaws.com/mailroom:${{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="weni-flows/mailroom" PATCH_TARGET="deployment.json"
for e in ${{github.event.inputs.destination-env}}; 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-platform
directory: ./kubernetes-manifests/
branch: main
message: "From Rapidpro Mailroom Build (Dispatch)"

- name: Generated Image URL to Copy
run: |
echo ${{ env.IMAGE_TAG }}
Loading