AppBuilder Agent #410
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
name: AppBuilder Agent | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: "Log Level" | |
required: true | |
default: "warning" | |
tags: | |
description: "Tags" | |
schedule: | |
- cron: "0 0 * * 0" # weekly | |
env: | |
BUILD_TAG: build-appbuilder-agent:latest | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Show environment | |
run: env | |
- name: Determine docker tags | |
id: meta | |
run: | | |
DOCKER_TAG=latest | |
if [[ "${GITHUB_HEAD_REF}" != "" ]]; then BRANCH="${GITHUB_HEAD_REF}"; else BRANCH="${GITHUB_REF_NAME}"; fi | |
case $BRANCH in develop) APP_ENV="stg" ;; master) APP_ENV="prd" ;; *) APP_ENV="stg" && DOCKER_TAG="${BRANCH/\//-}" ;; esac | |
echo "Branch=${BRANCH}" | |
echo "DockerTag=${DOCKER_TAG}" | |
echo "AppEnv=${APP_ENV}" | |
echo "Branch=${BRANCH}" >> $GITHUB_OUTPUT | |
echo "DockerTag=${DOCKER_TAG}" >> $GITHUB_OUTPUT | |
echo "AppEnv=${APP_ENV}" >> $GITHUB_OUTPUT | |
- name: Build docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
load: true | |
tags: ${{ env.BUILD_TAG }} | |
- name: Get version | |
id: version | |
run: | | |
docker images | |
mkdir $HOME/out | |
id=$(docker create ${{ env.BUILD_TAG }}) | |
docker cp $id:/app-builders/VERSION $HOME/out | |
docker rm -v $id | |
echo "VersionTag=$(cat $HOME/out/VERSION)" >> $GITHUB_OUTPUT | |
- name: Configure AWS credentials (SIL) | |
id: aws_sil | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.SIL__AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.SIL__AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.SIL__AWS_DEFAULT_REGION }} | |
- name: Login to AWS ECR (SIL) | |
id: ecr_sil | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
registries: ${{ secrets.SIL__AWS_ECR_ACCOUNT }} | |
- name: Push to AWS ECR (SIL) | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
"${{ steps.ecr_sil.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
"${{ steps.ecr_sil.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
- name: Configure AWS credentials (FCBH) | |
if: ${{ steps.meta.outputs.AppEnv == 'prd' }} | |
id: aws_fcbh | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.FCBH__AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.FCBH__AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.FCBH__AWS_DEFAULT_REGION }} | |
- name: Login to AWS ECR (FCBH) | |
if: ${{ steps.meta.outputs.AppEnv == 'prd' }} | |
id: ecr_fcbh | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
registries: ${{ secrets.FCBH__AWS_ECR_ACCOUNT }} | |
- name: Push to AWS ECR (FCBH) | |
if: ${{ steps.meta.outputs.AppEnv == 'prd' }} | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
"${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
"${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
- name: Login to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push to GHCR | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
"ghcr.io/sillsdev/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
"ghcr.io/sillsdev/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
- name: Cleanup older untagged packages, keep 2 | |
uses: actions/delete-package-versions@v4 | |
with: | |
package-name: "appbuilder-agent-${{ steps.meta.outputs.AppEnv }}" | |
package-type: "container" | |
min-versions-to-keep: 2 | |
delete-only-untagged-versions: "true" | |
- name: Cleanup older all packages, keep 6 | |
uses: actions/delete-package-versions@v4 | |
with: | |
package-name: "appbuilder-agent-${{ steps.meta.outputs.AppEnv }}" | |
package-type: "container" | |
min-versions-to-keep: 6 |