diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..ab800ee --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,97 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + schedule: + - cron: '41 19 * * *' + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1 + with: + cosign-release: 'v2.1.1' + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..163127a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,15 @@ +trigger: +- master + +jobs: +- job: BuildDockerImage + pool: + vmImage: 'ubuntu-latest' + steps: + - task: Docker@2 + inputs: + containerRegistry: 'myregistry' + repository: 'my-iot-app' + command: 'buildAndPush' + Dockerfile: '**/Dockerfile' + tags: 'v1' diff --git a/IoT Plug and Play mobile.json b/IoT Plug and Play mobile.json new file mode 100644 index 0000000..adeba9c --- /dev/null +++ b/IoT Plug and Play mobile.json @@ -0,0 +1,409 @@ +[ + { + "@id": "dtmi:azureiot:PhoneAsADevice;2", + "@type": "Interface", + "contents": [ + { + "@type": "Component", + "displayName": { + "en": "Sensors" + }, + "name": "sensors", + "schema": "dtmi:azureiot:PhoneSensors;1" + }, + { + "@type": "Component", + "displayName": { + "en": "Device information" + }, + "name": "device_info", + "schema": "dtmi:azure:DeviceManagement:DeviceInformation;1" + }, + { + "@type": "Command", + "commandType": "synchronous", + "displayName": { + "en": "LightOn" + }, + "name": "lightOn", + "request": { + "@type": [ + "CommandPayload", + "Initialized" + ], + "displayName": { + "en": "Parameters" + }, + "name": "parameters", + "initialValue": { + "duration": 3, + "pulses": 2 + }, + "schema": { + "@type": "Object", + "displayName": { + "en": "Object" + }, + "fields": [ + { + "displayName": { + "en": "Duration" + }, + "name": "duration", + "schema": "integer" + }, + { + "displayName": { + "en": "Pulses interval" + }, + "name": "delay", + "schema": "integer" + }, + { + "displayName": { + "en": "Pulses" + }, + "name": "pulses", + "schema": "integer" + } + ] + } + } + }, + { + "@type": [ + "Property", + "StringValue" + ], + "displayName": { + "en": "Cloud property" + }, + "name": "writeableProp", + "schema": "string", + "writable": true + }, + { + "@type": [ + "Property", + "StringValue" + ], + "displayName": { + "en": "Editable property" + }, + "name": "readOnlyProp", + "schema": "string" + } + ], + "displayName": { + "en": "IoT Plug and Play mobile" + }, + "@context": [ + "dtmi:iotcentral:context;2", + "dtmi:dtdl:context;2" + ] + }, + { + "@context": [ + "dtmi:iotcentral:context;2", + "dtmi:dtdl:context;2" + ], + "@id": "dtmi:azureiot:PhoneSensors;1", + "@type": "Interface", + "contents": [ + { + "@type": "Telemetry", + "comment": "Level percentage", + "displayName": { + "en": "Battery Level" + }, + "name": "battery", + "schema": "integer" + }, + { + "@type": [ + "Telemetry", + "AccelerationVector" + ], + "displayName": { + "en": "Acceleration" + }, + "name": "accelerometer", + "schema": "vector" + }, + { + "@type": "Telemetry", + "displayName": { + "en": "Rotation" + }, + "name": "gyroscope", + "schema": "vector" + }, + { + "@type": "Telemetry", + "displayName": { + "en": "Magnetic induction" + }, + "name": "magnetometer", + "schema": "vector" + }, + { + "@type": [ + "Telemetry", + "Pressure" + ], + "displayName": { + "en": "Pressure" + }, + "name": "barometer", + "schema": "double", + "unit": "kilopascal" + }, + { + "@type": [ + "Telemetry", + "Location" + ], + "displayName": { + "en": "Location" + }, + "name": "geolocation", + "schema": "geopoint" + }, + { + "@type": "Command", + "commandType": "synchronous", + "displayName": { + "en": "Enable Sensors" + }, + "name": "enableSensors", + "request": { + "@type": "CommandPayload", + "displayName": { + "en": "Sensor" + }, + "name": "sensor", + "schema": { + "@type": "Object", + "displayName": { + "en": "Sensor" + }, + "fields": [ + { + "displayName": { + "en": "Sensor" + }, + "name": "sensor", + "schema": "dtmi:azureiot:PhoneSensors:SensorsEnum;1" + }, + { + "displayName": { + "en": "Enable" + }, + "name": "enable", + "schema": "boolean" + } + ] + } + } + }, + { + "@type": "Command", + "commandType": "synchronous", + "displayName": { + "en": "Change Delivery Interval" + }, + "name": "changeInterval", + "request": { + "@type": "CommandPayload", + "displayName": { + "en": "Payload" + }, + "name": "payload", + "schema": { + "@type": "Object", + "displayName": { + "en": "Sensor" + }, + "fields": [ + { + "displayName": { + "en": "Sensor" + }, + "name": "sensor", + "schema": "dtmi:azureiot:PhoneSensors:SensorsEnum;1" + }, + { + "displayName": { + "en": "Interval" + }, + "name": "interval", + "schema": "integer" + } + ] + } + } + } + ], + "displayName": { + "en": "Sensors" + }, + "schemas": [ + { + "@id": "dtmi:azureiot:PhoneSensors:SensorsEnum;1", + "@type": "Enum", + "displayName": { + "en": "Enum" + }, + "enumValues": [ + { + "displayName": { + "en": "Acceleration" + }, + "enumValue": "accelerometer", + "name": "Acceleration" + }, + { + "displayName": { + "en": "Pressure" + }, + "enumValue": "barometer", + "name": "Pressure" + }, + { + "displayName": { + "en": "Rotation" + }, + "enumValue": "gyroscope", + "name": "Rotation" + }, + { + "displayName": { + "en": "Magnetic Induction" + }, + "enumValue": "magnetometer", + "name": "MagneticInduction" + }, + { + "displayName": { + "en": "Location" + }, + "enumValue": "geolocation", + "name": "Location" + }, + { + "displayName": { + "en": "Battery Level" + }, + "enumValue": "battery", + "name": "Battery" + } + ], + "valueSchema": "string" + } + ] + }, + { + "@context": [ + "dtmi:iotcentral:context;2", + "dtmi:dtdl:context;2" + ], + "@id": "dtmi:azure:DeviceManagement:DeviceInformation;1", + "@type": "Interface", + "contents": [ + { + "@type": [ + "Property", + "StringValue" + ], + "description": { + "en": "Company name of the device manufacturer. This could be the same as the name of the original equipment manufacturer (OEM). Ex. Contoso." + }, + "displayName": { + "en": "Device manufacturer" + }, + "name": "manufacturer", + "schema": "string" + }, + { + "@type": "Property", + "description": { + "en": "Device model name or ID. Ex. Surface Book 2." + }, + "displayName": { + "en": "Device model" + }, + "name": "model", + "schema": "string" + }, + { + "@type": "Property", + "description": { + "en": "Version of the software on your device. This could be the version of your firmware. Ex. 1.3.45" + }, + "displayName": { + "en": "Software version" + }, + "name": "swVersion", + "schema": "string" + }, + { + "@type": "Property", + "description": { + "en": "Name of the operating system on the device. Ex. Windows 10 IoT Core." + }, + "displayName": { + "en": "Operating system name" + }, + "name": "osName", + "schema": "string" + }, + { + "@type": "Property", + "description": { + "en": "Architecture of the processor on the device. Ex. x64 or ARM." + }, + "displayName": { + "en": "Processor architecture" + }, + "name": "processorArchitecture", + "schema": "string" + }, + { + "@type": "Property", + "description": { + "en": "Name of the manufacturer of the processor on the device. Ex. Intel." + }, + "displayName": { + "en": "Processor manufacturer" + }, + "name": "processorManufacturer", + "schema": "string" + }, + { + "@type": "Property", + "description": { + "en": "Total available storage on the device in kilobytes. Ex. 2048000 kilobytes." + }, + "displayName": { + "en": "Total storage" + }, + "name": "totalStorage", + "schema": "double" + }, + { + "@type": "Property", + "description": { + "en": "Total available memory on the device in kilobytes. Ex. 256000 kilobytes." + }, + "displayName": { + "en": "Total memory" + }, + "name": "totalMemory", + "schema": "double" + } + ], + "displayName": { + "en": "Device Information" + } + } +] \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..163127a --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,15 @@ +trigger: +- master + +jobs: +- job: BuildDockerImage + pool: + vmImage: 'ubuntu-latest' + steps: + - task: Docker@2 + inputs: + containerRegistry: 'myregistry' + repository: 'my-iot-app' + command: 'buildAndPush' + Dockerfile: '**/Dockerfile' + tags: 'v1' diff --git a/iot.dockerfile b/iot.dockerfile new file mode 100644 index 0000000..d9898b0 --- /dev/null +++ b/iot.dockerfile @@ -0,0 +1,17 @@ +# Use an appropriate base image +FROM node:14 + +# Set the working directory +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy application files +COPY . . + +# Specify the command to run your application +CMD [ "node", "app.js" ]