Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Publish docker images for all branches as snapshots to private ECR registry (#2091)

Eric Bariaux07711ea667a7
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index 88997ea6f..4ae7fa590 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -90,6 +90,9 @@ on:
SECRETS:
required: false
+permissions:
+ id-token: write
+
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
@@ -400,7 +403,7 @@ jobs:
inputEnv = os.getenv('INPUT_ENVIRONMENT')
managerVersion = os.getenv('MANAGER_VERSION')
- if eventName == 'workflow_dispatch' and refType != 'tag':
+ if eventName == 'workflow_dispatch' and refType != 'tag' and inputEnv and inputEnv.strip():
if isMainRepo:
tag=inputTag
if not inputTag:
@@ -447,16 +450,15 @@ jobs:
if [ "$(uname -m)" == "aarch64" ]; then
PLATFORM=linux/aarch64
- OTHER_PLATFORM=linux/amd64
fi
if [ -n "$MANAGER_TAGS" ] || [[ "$DEPLOYMENTS" == *"#ref"* ]] || [ -n "$TEST_UI_CMD" ]; then
if [ -n "$MANAGER_TAGS" ]; then
command="docker build --push --build-arg GIT_COMMIT=$commitSha --platform linux/amd64,linux/aarch64 $MANAGER_TAGS $buildPath && docker build --build-arg GIT_COMMIT=$commitSha --platform ${PLATFORM:-linux/amd64} --load -t openremote/manager:$commitShaShort $buildPath"
- echo "pushRequired=true" >> $GITHUB_OUTPUT
+ echo "pushToDockerHub=true" >> $GITHUB_OUTPUT
echo "managerDockerImage=openremote/manager:$FIRST_MANAGER_TAG" >> $GITHUB_OUTPUT
else
- command="docker build --build-arg GIT_COMMIT=$commitSha --platform ${PLATFORM:-linux/amd64} --load -t openremote/manager:$commitShaShort $buildPath && docker build --build-arg GIT_COMMIT=$commitSha --platform ${OTHER_PLATFORM:-linux/aarch64} -t openremote/manager:$commitShaShort $buildPath"
+ command="docker build --push --build-arg GIT_COMMIT=$commitSha --platform linux/amd64,linux/aarch64 -t ${{ secrets.OR_AWS_DEVELOPERS_ACCOUNT_ID }}.dkr.ecr.eu-west-1.amazonaws.com/openremote/manager:SNAPSHOT-$commitShaShort $buildPath && docker build --build-arg GIT_COMMIT=$commitSha --platform ${PLATFORM:-linux/amd64} --load -t openremote/manager:$commitShaShort $buildPath"
echo "managerDockerImage=openremote/manager:$commitShaShort" >> $GITHUB_OUTPUT
fi
echo "value=$command" >> $GITHUB_OUTPUT
@@ -523,12 +525,23 @@ jobs:
DEPLOYMENT_DOCKER_CMD: ${{ steps.deployment-docker-command.outputs.value }}
- name: Login to DockerHub
- if: ${{ steps.manager-docker-command.outputs.pushRequired == 'true' }}
+ if: ${{ steps.manager-docker-command.outputs.pushToDockerHub == 'true' }}
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
with:
username: ${{ steps.inputs-and-secrets.outputs._TEMP_DOCKERHUB_USER }}
password: ${{ steps.inputs-and-secrets.outputs._TEMP_DOCKERHUB_PASSWORD }}
+ - name: Configure AWS Credentials
+ if: ${{ steps.manager-docker-command.outputs.pushToDockerHub != 'true' }}
+ uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0
+ with:
+ aws-region: eu-west-1
+ role-to-assume: "arn:aws:iam::${{ secrets.OR_AWS_DEVELOPERS_ACCOUNT_ID }}:role/${{ secrets.OR_GH_AWS_ECR_PUSH_ROLE }}"
+
+ - name: Login to private ECR
+ if: ${{ steps.manager-docker-command.outputs.pushToDockerHub != 'true' }}
+ uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
+
- name: set up QEMU
if: ${{ steps.manager-docker-command.outputs.value != '' || steps.deployment-docker-command.outputs.value != '' }}
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3
@@ -762,7 +775,7 @@ jobs:
path: ui/app/*/app-test-report/**
- name: Scan manager docker image
- if: steps.manager-docker-command.outputs.pushRequired == 'true'
+ if: steps.manager-docker-command.outputs.pushToDockerHub == 'true'
uses: anchore/scan-action@2c901ab7378897c01b8efaa2d0c9bf519cc64b9e # v6.2.0
id: manager-anchore-scan
with:
@@ -773,7 +786,7 @@ jobs:
- name: Upload Anchore scan SARIF report
if: |
!cancelled() &&
- steps.manager-docker-command.outputs.pushRequired == 'true'
+ steps.manager-docker-command.outputs.pushToDockerHub == 'true'
uses: github/codeql-action/upload-sarif@e488e3c8239c26bf8e6704904a8cb59be658d450 # v3
with:
sarif_file: ${{ steps.manager-anchore-scan.outputs.sarif }}
@@ -781,7 +794,7 @@ jobs:
- name: Inspect Anchore scan SARIF report
if: |
!cancelled() &&
- steps.manager-docker-command.outputs.pushRequired == 'true'
+ steps.manager-docker-command.outputs.pushToDockerHub == 'true'
run: cat ${{ steps.manager-anchore-scan.outputs.sarif }}
- name: Run maven publish command