100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Temp (#626)
Rich Turner47d3dbf804a0
diff --git a/.ci_cd/deploy.sh b/.ci_cd/deploy.shindex 6ed263cd7..4285a0085 100644--- a/.ci_cd/deploy.sh+++ b/.ci_cd/deploy.sh@@ -1,5 +1,10 @@#!/bin/bash+revoke_ssh () {+ aws ec2 revoke-security-group-ingress --group-name ssh-access --protocol tcp --port 22 --cidr $IPV4/32+ echo "Revoked AWS SSH access"+}+if [ -f "temp/env" ]; thenecho "Loading environment variables: 'temp/env'"set -a@@ -56,10 +61,43 @@ if [ ! -z "$SSH_USER" ]; thenhostStr="${SSH_USER}@$hostStr"fi+# Grant SSH access to this runner's public IP on AWS+SSH_GRANTED='false'+if [ ! -z "$AWS_KEY" -a ! -z "$AWS_SECRET" -a ! -z "$IPV4" ]; then+ echo "Granting SSH access to this runner's public IP on AWS"+ if [ -z "$AWS_REGION" ]; then+ AWS_REGION="eu-west-1"+ fi+ echo "Logging into AWS"+ aws configure set aws_access_key_id $AWS_KEY+ aws configure set aws_secret_access_key $AWS_SECRET+ aws configure set region $AWS_REGION+ aws sts get-caller-identity 1>/dev/null 2>/dev/null+ if [ $? -ne 0 ]; then+ echo "Failed to login to AWS"+ return+ else+ echo "Login succeeded"+ fi+ # Add this github runner to ssh-access security group for SSH access+ aws ec2 authorize-security-group-ingress --group-name ssh-access --protocol tcp --port 22 --cidr $IPV4/32+ if [ $? -ne 0 ]; then+ echo "SSH Access failed might not be able to SSH into host(s)"+ else+ echo "SSH Access granted for this runner"+ SSH_GRANTED='true'+ fi+else+ echo "AWS_KEY, AWS_SECRET and or IPV4 not set so cannot grant SSH access"+fi+# Get host platformPLATFORM=$($sshCommandPrefix $hostStr -- uname -m)if [ "$?" != 0 -o -z "$PLATFORM" ]; thenecho "Failed to determine host platform"+ if [ "$SSH_GRANTED" == 'true' ]; then+ revoke_ssh+ fiexit 1fiif [ "$PLATFORM" == "x86_64" ]; then@@ -72,6 +110,9 @@ if [ "$MANAGER_TAG" != '#ref' ]; thendocker manifest inspect openremote/manager:$MANAGER_TAG > /dev/null 2> /dev/nullif [ $? -ne 0 ]; thenecho "Specified manager tag does not exist in docker hub"+ if [ "$SSH_GRANTED" == 'true' ]; then+ revoke_ssh+ fiexit 1fielse@@ -81,6 +122,9 @@ elsedocker build -o type=docker,dest=- --build-arg GIT_REPO=$REPO_NAME --build-arg GIT_COMMIT=$MANAGER_REF --platform $PLATFORM -t openremote/manager:$MANAGER_REF $MANAGER_DOCKER_BUILD_PATH | gzip > temp/manager.tar.gzif [ $? -ne 0 -o ! -f temp/manager.tar.gz ]; thenecho "Failed to export manager image with tag: $MANAGER_REF"+ if [ "$SSH_GRANTED" == 'true' ]; then+ revoke_ssh+ fiexit 1fifi@@ -90,6 +134,9 @@ if [ ! -z "$DEPLOYMENT_REF" ]; thendocker build -o type=docker,dest=- --build-arg GIT_REPO=$REPO_NAME --build-arg GIT_COMMIT=$DEPLOYMENT_REF --platform $PLATFORM -t openremote/deployment:$DEPLOYMENT_REF $DEPLOYMENT_DOCKER_BUILD_PATH | gzip > temp/deployment.tar.gzif [ $? -ne 0 -o ! -f temp/deployment.tar.gz ]; thenecho "Failed to export deployment image"+ if [ "$SSH_GRANTED" == 'true' ]; then+ revoke_ssh+ fiexit 1fifi@@ -232,6 +279,9 @@ EOFif [ $? -ne 0 ]; thenecho "Deployment failed or is unhealthy"+ if [ "$SSH_GRANTED" == 'true' ]; then+ revoke_ssh+ fiexit 1fi@@ -239,5 +289,12 @@ echo "Testing manager web server https://$HOST..."response=$(curl --output /dev/null --silent --head --write-out "%{http_code}" https://$HOST/manager/)if [ $response -ne 200 ]; thenecho "Response code = $response"+ if [ "$SSH_GRANTED" == 'true' ]; then+ revoke_ssh+ fiexit 1fi++if [ "$SSH_GRANTED" == 'true' ]; then+ revoke_ssh+fidiff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex 4f04eb532..0205ece55 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -160,6 +160,10 @@ jobs:INPUTS: ${{ toJSON(github.event.inputs) }}EVENT_NAME: ${{ github.event_name }}+ - name: Public IP+ id: ip-address+ uses: haythem/[email protected]+- name: Checkoutuses: actions/checkout@v2with:@@ -602,11 +606,12 @@ jobs:- name: Determine deploy script commandid: deploy-script-commandif: ${{ steps.deployments.outputs.value != '' && steps.check_deployment_script.outputs.files_exists != 'true' }}+ shell: bashrun: |if [ -f ".ci_cd/deploy.sh" ]; then- echo ::set-output name=value::bash .ci_cd/deploy.sh"+ echo "::set-output name=value::bash .ci_cd/deploy.sh"elif [ "$IS_CUSTOM_PROJECT" == 'true' -a -f "openremote/.ci_cd/deploy.sh" ]; then- echo ::set-output name=value::bash openremote/.ci_cd/deploy.sh"+ echo "::set-output name=value::bash openremote/.ci_cd/deploy.sh"elseecho "Cannot find deploy bash script"exit 1@@ -675,6 +680,8 @@ jobs:# Output inputs and secrets (spacial handling for SSH_KEY and SSH_PASSWORD)# _ENV_ prefixed keys are output last (to override any non env specific keys)for key, value in inputsAndSecrets.items():+ if "." in key:+ continueif key.startswith("_"):continueos.system(f"echo 'Secret found {key}...'")@@ -691,6 +698,8 @@ jobs:os.system(f"echo '{key}=\"{value}\"' >> temp/env")for key, value in inputsAndSecrets.items():+ if "." in key:+ continueif not key.startswith("_"):continueenvironment = (env if env else "").upper()@@ -733,3 +742,5 @@ jobs:DEPLOYMENT_REF: ${{ steps.deployment-docker-command.outputs.refTag }}INPUTS_AND_SECRETS: ${{ toJSON(steps.inputs-and-secrets.outputs) }}DEPLOY_SCRIPT_COMMAND: ${{ steps.deploy-script-command.outputs.value }}+ IPV4: ${{ steps.ip-address.outputs.ipv4 }}+ IPV6: ${{ steps.ip-address.outputs.ipv6 }}