Push to LU AWS Account #486
This file contains hidden or 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-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - 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: Extract versions from builder image | |
| id: versions | |
| run: | | |
| # Pull the builder image and extract versions.json | |
| docker pull ghcr.io/sillsdev/app-builders:latest | |
| CONTAINER_ID=$(docker create ghcr.io/sillsdev/app-builders:latest /bin/true) | |
| docker cp ${CONTAINER_ID}:/versions.json ./versions.json | |
| docker rm ${CONTAINER_ID} | |
| # Parse versions.json using jq and set outputs | |
| echo "Contents of versions.json:" | |
| cat ./versions.json | |
| VERSION_SAB=$(jq -r '.scriptureappbuilder' ./versions.json) | |
| VERSION_RAB=$(jq -r '.readingappbuilder' ./versions.json) | |
| VERSION_DAB=$(jq -r '.dictionaryappbuilder' ./versions.json) | |
| VERSION_KAB=$(jq -r '.keyboardappbuilder' ./versions.json) | |
| echo "Extracted versions:" | |
| echo " scriptureappbuilder: $VERSION_SAB" | |
| echo " readingappbuilder: $VERSION_RAB" | |
| echo " dictionaryappbuilder: $VERSION_DAB" | |
| echo " keyboardappbuilder: $VERSION_KAB" | |
| echo "VERSION_SAB=$VERSION_SAB" >> $GITHUB_OUTPUT | |
| echo "VERSION_RAB=$VERSION_RAB" >> $GITHUB_OUTPUT | |
| echo "VERSION_DAB=$VERSION_DAB" >> $GITHUB_OUTPUT | |
| echo "VERSION_KAB=$VERSION_KAB" >> $GITHUB_OUTPUT | |
| - name: Build docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| load: true | |
| tags: ${{ env.BUILD_TAG }} | |
| build-args: | | |
| VERSION_SAB=${{ steps.versions.outputs.VERSION_SAB }} | |
| VERSION_RAB=${{ steps.versions.outputs.VERSION_RAB }} | |
| VERSION_DAB=${{ steps.versions.outputs.VERSION_DAB }} | |
| VERSION_KAB=${{ steps.versions.outputs.VERSION_KAB }} | |
| - 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@v4 | |
| 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@v2 | |
| with: | |
| registries: ${{ secrets.SIL__AWS_ECR_ACCOUNT }} | |
| - name: Push to AWS ECR (SIL) | |
| run: | | |
| docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
| docker push "${{ steps.ecr_sil.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker push "${{ 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@v4 | |
| 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@v2 | |
| with: | |
| registries: ${{ secrets.FCBH__AWS_ECR_ACCOUNT }} | |
| - name: Push to AWS ECR (FCBH) | |
| if: ${{ steps.meta.outputs.AppEnv == 'prd' }} | |
| run: | | |
| docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
| docker push "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker push "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
| - name: Configure AWS credentials (LU) | |
| if: ${{ steps.meta.outputs.AppEnv == 'stg' }} | |
| id: aws_lu | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.LU__AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.LU__AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ secrets.LU__AWS_DEFAULT_REGION }} | |
| - name: Login to AWS ECR (LU) | |
| if: ${{ steps.meta.outputs.AppEnv == 'stg' }} | |
| id: ecr_lu | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| with: | |
| registries: ${{ secrets.LU__AWS_ECR_ACCOUNT }} | |
| - name: Push to AWS ECR (LU) | |
| if: ${{ steps.meta.outputs.AppEnv == 'stg' }} | |
| run: | | |
| docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
| docker push "${{ steps.ecr_lu.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker push "${{ steps.ecr_lu.outputs.registry }}/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Push to GHCR | |
| run: | | |
| docker tag ${{ env.BUILD_TAG }} "ghcr.io/sillsdev/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker tag ${{ env.BUILD_TAG }} "ghcr.io/sillsdev/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.version.outputs.VersionTag }}" | |
| docker push "ghcr.io/sillsdev/appbuilder-agent-${{ steps.meta.outputs.AppEnv }}:${{ steps.meta.outputs.DockerTag }}" | |
| docker push "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@v5 | |
| 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@v5 | |
| with: | |
| package-name: "appbuilder-agent-${{ steps.meta.outputs.AppEnv }}" | |
| package-type: "container" | |
| min-versions-to-keep: 6 |