@@ -4,7 +4,7 @@ name: Build
44on :
55 push :
66 paths-ignore :
7- - ' .github/workflows/**'
7+ - " .github/workflows/**"
88 workflow_dispatch :
99
1010jobs :
@@ -16,13 +16,10 @@ jobs:
1616 uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
1717
1818 - name : Install cloc
19- run : sudo apt update && sudo apt install cloc -y
19+ run : sudo apt update && sudo apt install -y cloc
2020
2121 - name : Print lines of code
22- run : |
23- cloc --include-lang \
24- C#,SQL,Razor,"Bourne Shell",PowerShell,HTML,CSS,Sass,JavaScript,TypeScript \
25- --vcs git
22+ run : cloc --include-lang C#,SQL,Razor,"Bourne Shell",PowerShell,HTML,CSS,Sass,JavaScript,TypeScript --vcs git
2623
2724
2825 build-artifacts :
@@ -40,15 +37,15 @@ jobs:
4037 echo "GitHub event: $GITHUB_EVENT"
4138
4239 - name : Restore/Clean service
43- working-directory : ./ src/KeyConnector
40+ working-directory : src/KeyConnector
4441 run : |
4542 echo "Restore"
4643 dotnet restore
4744 echo "Clean"
4845 dotnet clean -c "Release" -o obj/build-output/publish
4946
5047 - name : Publish service
51- working-directory : ./ src/KeyConnector
48+ working-directory : src/KeyConnector
5249 run : |
5350 echo "Publish"
5451 dotnet publish -c "Release" -o obj/build-output/publish
6259 uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
6360 with :
6461 name : KeyConnector.zip
65- path : ./ src/KeyConnector/KeyConnector.zip
62+ path : src/KeyConnector/KeyConnector.zip
6663 if-no-files-found : error
6764
6865
@@ -71,18 +68,34 @@ jobs:
7168 runs-on : ubuntu-22.04
7269 needs : build-artifacts
7370 env :
74- _SERVICE_NAME : key-connector
71+ _AZ_REGISTRY : bitwardenprod.azurecr.io
72+ _PROJECT_NAME : key-connector
7573 steps :
7674 - name : Checkout repo
7775 uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
7876
79- - name : Setup DCT
80- id : setup-dct
81- if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc'
82- uses : bitwarden/gh-actions/setup-docker-trust@main
77+ - name : Login to Azure - PROD Subscription
78+ uses : Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
8379 with :
84- azure-creds : ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
85- azure-keyvault-name : " bitwarden-ci"
80+ creds : ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
81+
82+ - name : Login to PROD ACR
83+ run : az acr login -n ${_AZ_REGISTRY%.azurecr.io}
84+
85+ - name : Generate Docker image tag
86+ id : tag
87+ run : |
88+ IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g") # slash safe branch name
89+ if [[ "$IMAGE_TAG" == "master" ]]; then
90+ IMAGE_TAG=dev
91+ fi
92+ echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
93+
94+ - name : Generate image full name
95+ id : image-name
96+ env :
97+ IMAGE_TAG : ${{ steps.tag.outputs.image_tag }}
98+ run : echo "name=${_AZ_REGISTRY}/${_PROJECT_NAME}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
8699
87100 - name : Get build artifact
88101 uses : actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
@@ -91,47 +104,14 @@ jobs:
91104
92105 - name : Setup build artifact
93106 run : |
94- mkdir -p ./src/KeyConnector/obj/build-output/publish
95- unzip KeyConnector.zip \
96- -d ./src/KeyConnector/obj/build-output/publish
97-
98- - name : Build Docker images
99- run : |
100- docker build -t ${{ env._SERVICE_NAME }} \
101- ./src/KeyConnector
102-
103- - name : Tag and Push RC to Docker Hub
104- if : (github.ref == 'refs/heads/rc')
105- env :
106- DOCKER_CONTENT_TRUST : 1
107- DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE : ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
108- run : |
109- docker tag ${{ env._SERVICE_NAME }} \
110- bitwarden/${{ env._SERVICE_NAME }}:rc
111- docker push bitwarden/${{ env._SERVICE_NAME }}:rc
107+ mkdir -p src/KeyConnector/obj/build-output/publish
108+ unzip KeyConnector.zip -d src/KeyConnector/obj/build-output/publish
112109
113- - name : Tag and Push Hotfix to Docker Hub
114- if : (github.ref == 'refs/heads/hotfix-rc')
115- env :
116- DOCKER_CONTENT_TRUST : 1
117- DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE : ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
118- run : |
119- docker tag ${{ env._SERVICE_NAME }} \
120- bitwarden/${{ env._SERVICE_NAME }}:hotfix
121- docker push bitwarden/${{ env._SERVICE_NAME }}:hotfix
122-
123- - name : Tag and Push Dev to Docker Hub
124- if : (github.ref == 'refs/heads/master')
125- env :
126- DOCKER_CONTENT_TRUST : 1
127- DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE : ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
128- run : |
129- docker tag ${{ env._SERVICE_NAME }} \
130- bitwarden/${{ env._SERVICE_NAME }}:dev
131- docker push bitwarden/${{ env._SERVICE_NAME }}:dev
132-
133- - name : Log out of Docker and disable Docker Notary
134- if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc'
135- run : |
136- docker logout
137- echo "DOCKER_CONTENT_TRUST=0" >> $GITHUB_ENV
110+ - name : Build Docker image
111+ uses : docker/build-push-action@1104d471370f9806843c095c1db02b5a90c5f8b6 # v3.3.1
112+ with :
113+ context : src/KeyConnector
114+ file : src/KeyConnector/Dockerfile
115+ platforms : linux/amd64
116+ push : true
117+ tags : ${{ steps.image-name.outputs.name }}
0 commit comments