-
-
Notifications
You must be signed in to change notification settings - Fork 1
137 lines (120 loc) · 4.69 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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:/usr/share/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