anchor.diff:  # For those usages not covered by the GNU Affero General Public License
   # please contact with: [daniel.moranjimenez@telefonica.com]
   
  -ARG  NODE_VERSION=10
  -
  -FROM node:${NODE_VERSION} AS build-env
  -
  +ARG NODE_VERSION=10
  +ARG TARGET=/opt/iotaul
   ARG GITHUB_ACCOUNT=telefonicaid
   ARG GITHUB_REPOSITORY=iotagent-ul
   ARG DOWNLOAD=latest
   ARG SOURCE_BRANCH=master
   
  +########################################################################################
  +#
  +# This build stage retrieves the source code from GitHub. The default download is the 
  +# latest tip of the master of the named repository on GitHub.
  +#
  +# To obtain the latest stable release run this Docker file with the parameters:
  +# --no-cache --build-arg DOWNLOAD=stable
  +#
  +# To obtain any specific version of a release run this Docker file with the parameters:
  +# --no-cache --build-arg DOWNLOAD=1.7.0
  +#
  +# For development purposes, to create a development image including a running Distro, 
  +# run this Docker file with the parameter:
  +#
  +# --target=builder
  +#
  +######################################################################################## 
  +FROM node:${NODE_VERSION} AS builder
  +ARG TARGET
  +ARG GITHUB_ACCOUNT
  +ARG GITHUB_REPOSITORY
  +ARG DOWNLOAD
  +ARG SOURCE_BRANCH
  +
   SHELL ["/bin/bash", "-o", "pipefail", "-c"]
   
  -# IMPORTANT: For production environments use Docker Secrets to protect values of the sensitive ENV 
  -# variables defined below, by adding _FILE to the name of the relevant variable.
  +# As an Alternative for local development, just copy this Dockerfile into file the root of 
  +# the repository and replace the whole RUN statement below by the following COPY statement 
  +# in your local source using :
   #
  -# - IOTA_AUTH_USER, IOTA_AUTH_PASSWORD - when using Keystone Security 
  -# - IOTA_AUTH_CLIENT_ID, IOTA_AUTH_CLIENT_SECRET - when using OAuth2 Security
  -
  -#
  -# The following RUN command retrieves the source code from GitHub.
  -# 
  -# To obtain the latest stable release run this Docker file with the parameters
  -# --no-cache --build-arg DOWNLOAD=stable
  -# To obtain any speciifc version of a release run this Docker file with the parameters
  -# --no-cache --build-arg DOWNLOAD=1.7.0
  -#
  -# The default download is the latest tip of the master of the named repository on GitHub
  -#
  -# Alternatively for local development, just copy this Dockerfile into file the root of the repository and 
  -# replace the whole RUN statement by the following COPY statement in your local source using :
  -#
  -# COPY . /opt/iotaul/
  +# COPY . ${TARGET}/
   #
   
   # hadolint ignore=DL3008
  -RUN apt-get update && \
  -	# Ensure that unzip and curl are installed
  -	apt-get install -y --no-install-recommends unzip ca-certificates curl && \
  +RUN \
  +	# Ensure that unzip is installed prior to downloading
  +	apt-get install -y --no-install-recommends unzip && \
   	if [ "${DOWNLOAD}" = "latest" ] ; \
   	then \
   		RELEASE="${SOURCE_BRANCH}"; \
  
positive.code: 
  USER node
  ENV NODE_ENV=development
  
  # Expose 4061 for NORTH PORT, 7896 for HTTP PORT
  EXPOSE ${IOTA_NORTH_PORT:-4061} ${IOTA_HTTP_PORT:-7896}
  CMD ["node", "/opt/iotaul/bin/iotagent-ul", "-- ", "config.js"]
  HEALTHCHECK --interval=30s --timeout=3s --start-period=10s \
     CMD npm run healthcheck
  
  
  # Install PM2
  FROM node:${NODE_VERSION} AS pm2-install
  COPY --from=build-env /opt/iotaul /opt/iotaul
  # hadolint ignore=DL3008,DL3016
  RUN npm install pm2@4.4.0 -g --no-package-lock --no-optional
  
  USER node
  ENV NODE_ENV=development
  # Expose 4061 for NORTH PORT, 7896 for HTTP PORT
  EXPOSE ${IOTA_NORTH_PORT:-4061} ${IOTA_HTTP_PORT:-7896}
  CMD ["pm2-runtime", "/opt/iotaul/bin/iotagent-ul", "-- ", "config.js"]
  
  
  
  # Create an anonymous user
  FROM node:${NODE_VERSION} AS anon-user
  RUN sed -i -r "/^(root|nobody)/!d" /etc/passwd /etc/shadow /etc/group \
      && sed -i -r 's#^(.*):[^:]*$#\1:/sbin/nologin#' /etc/passwd
  
  #
  # The following creates a distroless build for production.
  #
  
  FROM gcr.io/distroless/nodejs:${NODE_VERSION}
  ARG GITHUB_ACCOUNT
  ARG GITHUB_REPOSITORY
  ARG NODE_VERSION
  
negative.code: LABEL "org.opencontainers.image.licenses"="AGPL-3.0-only"
  LABEL "org.opencontainers.image.title"="IoT Agent for the Ultralight 2.0 protocol"
  LABEL "org.opencontainers.image.description"="An Internet of Things Agent for the Ultralight 2.0 protocol (with AMQP, HTTP and MQTT transports). This IoT Agent is designed to be a bridge between Ultralight and the NGSI interface of a context broker."
  LABEL "org.opencontainers.image.source"="https://github.com/${GITHUB_ACCOUNT}/${GITHUB_REPOSITORY}"
  LABEL "org.nodejs.version"="${NODE_VERSION}"
  
  COPY --from=builder "${TARGET}" "${TARGET}"
  WORKDIR "${TARGET}"
  
  USER nobody
  ENV NODE_ENV=production
  # Expose 4061 for NORTH PORT, 7896 for HTTP PORT
  EXPOSE ${IOTA_NORTH_PORT:-4061} ${IOTA_HTTP_PORT:-7896}
  CMD ["./bin/iotagent-ul", "-- ", "config.js"]
  HEALTHCHECK  --interval=30s --timeout=3s --start-period=10s \
    CMD ["/nodejs/bin/node", "./bin/healthcheck"]
  
  