Skip to content

build_layer4

build_layer4 #240

name: "Build Branding Layer (4 of 4)"
on:
repository_dispatch:
types: [build_layer4, build_layer3_error]
env:
VERSION_STR: ${{ github.event.client_payload.image.tag }}
VER_NUM: ${{ github.event.client_payload.image.ver_num }}
FROM_LAYER: ${{ github.event.client_payload.image.layer3 }}
FROM_LAYER_TAG: ${{ github.event.client_payload.image.layer3tag }}
jobs:
build_result:
name: "Build Layer 3 Result [#${{ github.event.client_payload.run_number }}]"
runs-on: ubuntu-latest
env:
RUN_URL: "[Run #${{ github.event.client_payload.run_number }}](${{ github.event.client_payload.run_url }})"
steps:
- name: "Display Error Msg"
if: github.event.client_payload.error_msg != ''
run: |-
echo -e "::error::${RUN_URL}%0A${{ github.event.client_payload.error_msg }}"
exit 1
- name: "Display Success Msg"
if: github.event.client_payload.build_msg != ''
run: |-
echo -e "::notice::${RUN_URL}%0A${{ github.event.client_payload.build_msg }}"
#endjob build_result
build_cfg:
needs: [build_result]
runs-on: ubuntu-latest
environment: default
env:
REPO_UN: ${{ vars.REPO_UN }}
REPO_PW: ${{ secrets.REPO_PW }}
REPO_DL_DOMAIN: ${{ vars.REPO_DL_DOMAIN }}
outputs:
REPO_BUILD_ARGS: ${{ steps.config_step.outputs.REPO_BUILD_ARGS }}
REPO_FILEPATH: ${{ steps.config_step.outputs.REPO_FILEPATH }}
RUN_STATIC: ${{ steps.config_step.outputs.RUN_STATIC }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.repo.ref_name }}
- name: "Check if webstatic hash archive exists"
id: config_step
shell: bash
run: |-
HASH_ALL=$(./staticfiles-hash-calc.sh)
REPO_FILEPATH="engage/sitestatic/webstatic-${HASH_ALL}.tar.gz"
TAR_URL="https://${REPO_DL_DOMAIN}/${REPO_FILEPATH}"
# check repo to see if tar.gz present by using header-only curl cmd
# NOTE: curl with user/pw in URL will force GHA to mask the pw, causing curl to return 401.
# bash sub-shell magic to avoid exposing the pw in cmd line history via inline file-create & use.
# @see https://stackoverflow.com/questions/33794842/forcing-curl-to-get-a-password-from-the-environment
R=$(curl --silent -I --netrc-file <(cat <<<"machine ${REPO_DL_DOMAIN} login ${REPO_UN} password ${REPO_PW}") "${TAR_URL}")
# print out all headers
echo "${R}"
if [[ $(echo "${R}" | grep -E "^HTTP" | awk -F " " '{print $2}') == "200" ]]; then
echo "::notice::Found [${REPO_FILEPATH}] and passing into build args."
REPO_BUILD_ARGS=
REPO_BUILD_ARGS+='"REPO_UN=%REPO_UN",'
REPO_BUILD_ARGS+='"REPO_PW=%REPO_PW",'
REPO_BUILD_ARGS+='"REPO_DL_DOMAIN='"${REPO_DL_DOMAIN}"'",'
REPO_BUILD_ARGS+='"REPO_FILEPATH='"${REPO_FILEPATH}"'",'
echo "REPO_BUILD_ARGS=${REPO_BUILD_ARGS}" >> $GITHUB_OUTPUT
# save minutes/money if we do not need to run the webstatic stuff
echo "RUN_STATIC=0" >> $GITHUB_OUTPUT
else
echo "::notice::Creating [${REPO_FILEPATH}] in a later step for next time."
echo "REPO_FILEPATH=${REPO_FILEPATH}" >> $GITHUB_OUTPUT
echo "RUN_STATIC=1" >> $GITHUB_OUTPUT
fi
#endjob build_cfg
build_cfg_engage:
needs: [build_cfg]
runs-on: ubuntu-latest
environment: default
outputs:
DOCKERFILE2USE: ${{ steps.config_step.outputs.DOCKERFILE2USE }}
IMAGE_NAME: ${{ steps.config_step.outputs.IMAGE_NAME }}
IMAGE_TAG: ${{ steps.config_step.outputs.IMAGE_TAG }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.repo.ref_name }}
- name: "Config For Engage Build"
id: config_step
run: |-
DOCKERFILE2USE="docker/final-engage.dockerfile"
echo "DOCKERFILE2USE=${DOCKERFILE2USE}" >> $GITHUB_OUTPUT
IMAGE_NAME=${{ github.repository_owner }}/p4-engage
IMAGE_TAG=${VERSION_STR}
echo "::notice::Build: ${IMAGE_NAME}:${IMAGE_TAG}"
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
#endjob build_cfg_engage
trigger-build-engage:
runs-on: ubuntu-latest
needs: [build_cfg, build_cfg_engage]
environment: default
steps:
- name: "Trigger Container Build For Engage"
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CI_WEBHOOK_TOKEN }}
repository: istresearch/ci-docker
event-type: build-repo
client-payload: |-
{
"repo": {
"name": "${{ github.repository }}",
"ref_type": "${{ github.event.client_payload.repo.ref_type }}",
"ref_name": "${{ github.event.client_payload.repo.ref_name }}"
},
"image": {
"dockerfile": "${{ needs.build_cfg_engage.outputs.DOCKERFILE2USE }}",
"arch_allowed": "amd64 arm64",
"name": "${{ needs.build_cfg_engage.outputs.IMAGE_NAME }}",
"tag": "${{ needs.build_cfg_engage.outputs.IMAGE_TAG }}",
"build_args": [ ${{ needs.build_cfg.outputs.REPO_BUILD_ARGS }}
"FROM_STAGE=${{ env.FROM_LAYER }}",
"FROM_STAGE_TAG=${{ env.FROM_LAYER_TAG }}",
"VERSION_CI=${{ env.VER_NUM }}",
"VERSION_TAG=${{ needs.build_cfg_engage.outputs.IMAGE_TAG }}",
"RUN_WEB_STATIC_FILE_COLLECTOR=${{ needs.build_cfg.outputs.RUN_STATIC }}"
]
},
"deployment": {
"deploy_flag": "${{ github.ref_type == 'branch' }}",
"k8s": [ {
"project": "pulse-engage",
"container": "pulse-engage",
"deploy_msg": ""
}, {
"project": "pulse-engage-celery",
"container": "celery-base",
"deploy_msg": ""
}, {
"project": "pulse-engage-celery",
"container": "celery-msgs",
"deploy_msg": ""
} ]
},
"callback": {
"repository": "${{ github.repository }}",
"event_type": "build_layer5",
"error_type": "build_layer4_engage_error",
"payload": {
"repo": {
"ref_type": "${{ github.event.client_payload.repo.ref_type }}",
"ref_name": "${{ github.event.client_payload.repo.ref_name }}"
},
"image": {
"tag": "${{ needs.build_cfg_engage.outputs.IMAGE_TAG }}",
"ver_num": "${{ env.VER_NUM }}",
"layer4tag": "${{ needs.build_cfg_engage.outputs.IMAGE_TAG }}",
"layer4": "${{ needs.build_cfg_engage.outputs.IMAGE_NAME }}:${{ needs.build_cfg_engage.outputs.IMAGE_TAG }}",
"repo_filepath": "${{ github.event.client_payload.image.repo_filepath }}"
}
}
}
}
#endjob trigger-build-engage
build_cfg_generic:
needs: [build_cfg]
runs-on: ubuntu-latest
environment: default
outputs:
DOCKERFILE2USE: ${{ steps.config_step.outputs.DOCKERFILE2USE }}
IMAGE_NAME: ${{ steps.config_step.outputs.IMAGE_NAME }}
IMAGE_TAG: ${{ steps.config_step.outputs.IMAGE_TAG }}
BUILD_FLAG: ${{ steps.config_step.outputs.BUILD_FLAG }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.repo.ref_name }}
- name: "Config For Generic Build"
id: config_step
env:
REF_NAME: "${{ github.event.client_payload.repo.ref_name }}"
run: |-
DOCKERFILE2USE="docker/final-generic.dockerfile"
echo "DOCKERFILE2USE=${DOCKERFILE2USE}" >> $GITHUB_OUTPUT
IMAGE_NAME=${{ github.repository_owner }}/rapidpro
IMAGE_TAG=${VERSION_STR}-generic
echo "::notice::Build: ${IMAGE_NAME}:${IMAGE_TAG}"
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
if [[ "${{ github.event.client_payload.repo.ref_type }}" == "tag" ]]; then
BUILD_FLAG=1
elif [[ "${REF_NAME}" == "develop" ]]; then
BUILD_FLAG=1
elif [[ "${REF_NAME}" =~ dev[-\/].* ]]; then
BUILD_FLAG=0
else
BUILD_FLAG=0
fi
echo "BUILD_FLAG=${BUILD_FLAG}" >> $GITHUB_OUTPUT
#endjob build_cfg_generic
trigger-build-generic:
if: needs.build_cfg_generic.outputs.BUILD_FLAG == 1
runs-on: ubuntu-latest
needs: [build_cfg, build_cfg_generic]
environment: default
steps:
- name: "Trigger Container Build"
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CI_WEBHOOK_TOKEN }}
repository: istresearch/ci-docker
event-type: build-repo
client-payload: |-
{
"repo": {
"name": "${{ github.repository }}",
"ref_type": "${{ github.event.client_payload.repo.ref_type }}",
"ref_name": "${{ github.event.client_payload.repo.ref_name }}"
},
"image": {
"dockerfile": "${{ needs.build_cfg_generic.outputs.DOCKERFILE2USE }}",
"arch_allowed": "amd64 arm64",
"name": "${{ needs.build_cfg_generic.outputs.IMAGE_NAME }}",
"tag": "${{ needs.build_cfg_generic.outputs.IMAGE_TAG }}",
"build_args": [
"FROM_STAGE=${{ env.FROM_LAYER }}",
"FROM_STAGE_TAG=${{ env.FROM_LAYER_TAG }}",
"VERSION_CI=${{ env.VER_NUM }}",
"VERSION_TAG=${{ needs.build_cfg_generic.outputs.IMAGE_TAG }}"
]
},
"callback": {
"repository": "${{ github.repository }}",
"event_type": "build_generic_success",
"error_type": "build_generic_error"
}
}
#endjob trigger-build-generic
build_cfg_rp:
needs: [build_cfg]
runs-on: ubuntu-latest
environment: default
outputs:
DOCKERFILE2USE: ${{ steps.config_step.outputs.DOCKERFILE2USE }}
IMAGE_NAME: ${{ steps.config_step.outputs.IMAGE_NAME }}
IMAGE_TAG: ${{ steps.config_step.outputs.IMAGE_TAG }}
BUILD_FLAG: ${{ steps.config_step.outputs.BUILD_FLAG }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.repo.ref_name }}
- name: "Config For RP Build"
id: config_step
run: |-
DOCKERFILE2USE="docker/final-rp.dockerfile"
echo "DOCKERFILE2USE=${DOCKERFILE2USE}" >> $GITHUB_OUTPUT
IMAGE_NAME=${{ github.repository_owner }}/rapidpro
IMAGE_TAG=${VERSION_STR}
echo "::notice::Build: ${IMAGE_NAME}:${IMAGE_TAG}"
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
if [[ "${{ github.event.client_payload.repo.ref_type }}" == "tag" ]]; then
BUILD_FLAG=1
else
BUILD_FLAG=0
fi
echo "BUILD_FLAG=${BUILD_FLAG}" >> $GITHUB_OUTPUT
#endjob build_cfg_rp
trigger-build-rp:
if: needs.build_cfg_rp.outputs.BUILD_FLAG == 1
runs-on: ubuntu-latest
needs: [build_cfg, build_cfg_rp]
environment: default
steps:
- name: "Trigger Container Build For RP"
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CI_WEBHOOK_TOKEN }}
repository: istresearch/ci-docker
event-type: build-repo
client-payload: |-
{
"repo": {
"name": "${{ github.repository }}",
"ref_type": "${{ github.event.client_payload.repo.ref_type }}",
"ref_name": "${{ github.event.client_payload.repo.ref_name }}"
},
"image": {
"dockerfile": "${{ needs.build_cfg_rp.outputs.DOCKERFILE2USE }}",
"arch_allowed": "amd64 arm64",
"name": "${{ needs.build_cfg_rp.outputs.IMAGE_NAME }}",
"tag": "${{ needs.build_cfg_rp.outputs.IMAGE_TAG }}",
"build_args": [
"FROM_STAGE=${{ env.FROM_LAYER }}",
"FROM_STAGE_TAG=${{ env.FROM_LAYER_TAG }}",
"VERSION_CI=${{ env.VER_NUM }}",
"VERSION_TAG=${{ needs.build_cfg_rp.outputs.IMAGE_TAG }}"
]
},
"callback": {
"repository": "${{ github.repository }}",
"event_type": "build_rp_success",
"error_type": "build_rp_error"
}
}
#endjob trigger-build-rp