Skip to content

Commit

Permalink
Merge pull request #197 from FlowFuse/move-npm-org
Browse files Browse the repository at this point in the history
Move npm org
  • Loading branch information
hardillb authored Nov 8, 2023
2 parents fe1d75f + 2c736f3 commit 47ca4c9
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 61 deletions.
67 changes: 56 additions & 11 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@ jobs:
- uses: JS-DevTools/[email protected]
with:
token: ${{ secrets.NPM_PUBLISH_TOKEN }}

build_container:
needs: [publish]
runs-on: ubuntu-latest
steps:
# - name: wait for npm
# uses: gr2m/await-npm-package-version-action@v1
# with:
# package: "@flowforge/flowforge-device-agent"
# version: ${{ github.event.release.tag_name }}
# timeout: 300
# registry: https://registry.npmjs.org
- name: checkout
uses: actions/checkout@v3
- name: Docker Meta Data
Expand All @@ -47,20 +39,73 @@ jobs:
- name: docker login
uses: docker/[email protected]
with:
username: flowforge
username: flowfuse
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push FlowForge Device Agent container
- name: Build and push FlowFuse Device Agent container
uses: docker/[email protected]
with:
context: docker
file: docker/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
push: true
platforms: linux/amd64, linux/arm64, linux/arm/v7
- name: Publish README.md to Docker hub
uses: peter-evans/dockerhub-description@v3
with:
repository: flowfuse/device-agent
username: flowfuse
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
readme-filepath: ./docker/README.md
publish_legacy:
needs: [publish]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: "Install jq"
run: sudo apt-get install -y jq
- name: "Patch module name"
working-directory: helm
run: |
cat package.json | jq '.name = "@flowforge/flowforge-device-agent"' > package.json-patched
mv package.json-patched package.json
- run: npm install
- uses: JS-DevTools/[email protected]
with:
token: ${{ secrets.NPM_PUBLISH_TOKEN_FLOWFORGE }}
- name: Docker Meta Data
id: meta
uses: docker/metadata-action@v3
with:
tags: |
type=semver,event=tag,pattern={{version}}
flavor: |
latest=true
images: |
flowforge/device-agent
- name: Setup QEMU
uses: docker/[email protected]
- name: Setup Docker buildx
uses: docker/[email protected]
- name: docker login
uses: docker/[email protected]
with:
username: flowforge
password: ${{ secrets.DOCKER_HUB_PASSWORD_FLOWFORGE }}
- name: Build and push FlowFuse Device Agent container
uses: docker/[email protected]
with:
context: docker
file: docker/Dockerfile_flowforge
tags: ${{ steps.meta.outputs.tags }}
push: true
platforms: linux/amd64, linux/arm64, linux/arm/v7
- name: Publish README.md to Docker hub
uses: peter-evans/dockerhub-description@v3
with:
repository: flowforge/device-agent
username: flowforge
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
password: ${{ secrets.DOCKER_HUB_PASSWORD_FLOWFORGE }}
readme-filepath: ./docker/README.md
51 changes: 29 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ The Device Agent can be installed on most Linux distributions, Windows, and MacO

## Installing the Device Agent

The Device Agent is published to the public npm repository as [@flowforge/flowforge-device-agent](https://www.npmjs.com/package/@flowforge/flowforge-device-agent).
The Device Agent is published to the public npm repository as [@flowfuse/device-agent](https://www.npmjs.com/package/@flowfuse/device-agent).

It can be installed as a global npm module. This will ensure the agent
command is on the path:
It can be installed as a global npm module. This will ensure the agent command is on the path.

Note: previous versions of the agent were published as `@flowforge/flowforge-device-agent`.

### Linux/MacOS

```bash
sudo npm install -g @flowforge/flowforge-device-agent
sudo npm install -g @flowfuse/device-agent
```

### Windows

```bash
npm install -g @flowforge/flowforge-device-agent
npm install -g @flowfuse/device-agent
```

Or you can chose to run the Docker container. When you do, you'll need to mount
the `device.yml` obtained when [Registering the device](#register-the-device):
### Docker

We publish a Docker container for the Device Agent as `flowfuse/device-agent` on DockerHub.

When running with the container you will need to mount the `device.yml` obtained when [Registering the device](#register-the-device):

```bash
docker run --mount /path/to/device.yml:/opt/flowforge/device.yml -p 1880:1880 flowforge/device-agent:latest
docker run --mount /path/to/device.yml:/opt/flowfuse/device.yml -p 1880:1880 flowfuse/device-agent:latest
```

## Configuration
Expand All @@ -46,23 +50,26 @@ directory.

### Configuration directory

By default the agent uses `/opt/flowforge-device` or `c:\opt\flowforge-device` as
By default the agent uses `/opt/flowfuse-device` or `c:\opt\flowfuse-device` as
its working directory. This can be overridden with the `-d/--dir` option.

For backwards compatibility with previous versions, the agent will use `/opt/flowforge-device`
if it is exists, unless overridden on the command-line.

NOTE: The device agent will attempt to create the working directory if it is not found,
however if an error occurs, the device agent will exit and report a startup error.

#### Linux/MacOS

```bash
sudo mkdir /opt/flowforge-device
sudo chown -R $USER /opt/flowforge-device
sudo mkdir /opt/flowfuse-device
sudo chown -R $USER /opt/flowfuse-device
```

#### Windows (run elevated)

```bash
mkdir c:\opt\flowforge-device
mkdir c:\opt\flowfuse-device
```


Expand Down Expand Up @@ -127,9 +134,9 @@ to provide absolute paths to files containing the certificates/keys.

```yml
https:
keyPath: /opt/flowforge-device/certs/key.pem
certPath: /opt/flowforge-device/certs/cert.pem
caPath: /opt/flowforge-device/certs/ca.pem
keyPath: /opt/flowfuse-device/certs/key.pem
certPath: /opt/flowfuse-device/certs/cert.pem
caPath: /opt/flowfuse-device/certs/ca.pem
```
##### `httpStatic` configuration
Expand All @@ -139,17 +146,17 @@ This option can be used to serve content from a local directory.
If set to a path, the files in that directory will be served relative to `/`.

```yml
httpStatic: /opt/flowforge-device/static-content
httpStatic: /opt/flowfuse-device/static-content
```

It is also possible to configure it with a list of directories and the corresponding
path they should be served from.

```yml
httpStatic:
- path: /opt/flowforge-device/static-content/images
- path: /opt/flowfuse-device/static-content/images
root: /images
- path: /opt/flowforge-device/static-content/js
- path: /opt/flowfuse-device/static-content/js
root: /js
```

Expand Down Expand Up @@ -184,13 +191,13 @@ Extra options | Description
## Running

If the agent was installed as a global npm module, the command
`flowforge-device-agent` will be on the path.
`flowfuse-device-agent` will be on the path.

If the default working directory and config file are being used, then the agent
can be started with:

```
$ flowforge-device-agent
$ flowfuse-device-agent
```

For information about the available command-line arguments, run with `-h`:
Expand All @@ -199,7 +206,7 @@ For information about the available command-line arguments, run with `-h`:
Options
-c, --config file Device configuration file. Default: device.yml
-d, --dir dir Where the agent should store its state. Default: /opt/flowforge-device
-d, --dir dir Where the agent should store its state. Default: /opt/flowfuse-device
-i, --interval secs
-p, --port number
-m, --moduleCache Use local npm module cache rather than install
Expand Down Expand Up @@ -232,7 +239,7 @@ set of modules.
You can enable this mode by adding `-m` to the command line adding `moduleCache: true`
to the `device.yml` file. This will cause the Device Agent to load the modules from the
`module_cache` directory in the Device Agents Configuration directory as described above.
By default this will be `/opt/flowforge-device/module_cache`.
By default this will be `/opt/flowfuse-device/module_cache`.

### Creating a module cache

Expand Down
19 changes: 7 additions & 12 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
FROM node:16-alpine

ARG REGISTRY
ARG REGISTRY_TOKEN
ARG VERSION=latest

RUN if [[ ! -z "$REGISTRY_TOKEN" ]]; then echo "//$REGISTRY/:_authToken=$REGISTRY_TOKEN" >> ~/.npmrc ; fi
RUN if [[ ! -z "$REGISTRY" ]] ; then npm config set @flowforge:registry "https://$REGISTRY"; fi

RUN apk add --no-cache --virtual buildtools build-base linux-headers udev python3

RUN mkdir /opt/flowforge-device
RUN npm install -g @flowforge/flowforge-device-agent@${VERSION}
RUN mkdir /opt/flowfuse-device
RUN npm install -g @flowfuse/device-agent@${VERSION}

EXPOSE 1880

LABEL org.label-schema.name="Flowforge Device Agent" \
org.label-schema.url="https://flowforge.com" \
LABEL org.label-schema.name="FlowFuse Device Agent" \
org.label-schema.url="https://flowfuse.com" \
org.label-schema.vcs-type="Git" \
org.label-schema.vcs-url="https://github.com/flowforge/flowforge-device-agent" \
org.label-schema.vcs-url="https://github.com/FlowFuse/device-agent" \
org.label-schema.docker.dockerfile="docker/Dockerfile" \
org.schema-label.description="Collaborative, low code integration and automation environment" \
authors="Flowforge Inc."
authors="FlowFuse Inc."


CMD ["flowforge-device-agent"]
CMD ["flowfuse-device-agent"]
21 changes: 21 additions & 0 deletions docker/Dockerfile_flowforge
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:16-alpine

ARG VERSION=latest

RUN apk add --no-cache --virtual buildtools build-base linux-headers udev python3

RUN mkdir /opt/flowforge-device
RUN npm install -g @flowfuse/device-agent@${VERSION}

EXPOSE 1880

LABEL org.label-schema.name="FlowFuse Device Agent" \
org.label-schema.url="https://flowfuse.com" \
org.label-schema.vcs-type="Git" \
org.label-schema.vcs-url="https://github.com/FlowFuse/device-agent" \
org.label-schema.docker.dockerfile="docker/Dockerfile" \
org.schema-label.description="Collaborative, low code integration and automation environment" \
authors="FlowFuse Inc."


CMD ["flowfuse-device-agent"]
10 changes: 5 additions & 5 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# FlowForge Device Agent
# FlowFuse Device Agent

This container can be used to start a FlowForge device. The device needs to
be [registered on your FlowForge instance](https://flowforge.com/docs/user/devices/#register-the-device).
This container can be used to start a FlowFuse device. The device needs to
be [registered on your FlowFuse instance](https://flowfuse.com/docs/device-agent/register/).

The YAML with configuration needs to be mounted inside the container.

```
docker run -v /path/to/device.yml:/opt/flowforge-device/device.yml -p 1880:1880 flowforge/device-agent:latest
docker run -v /path/to/device.yml:/opt/flowfuse-device/device.yml -p 1880:1880 flowfuse/device-agent:latest
```

To run with verbose logging run as follows:

```
docker run -v /path/to/device.yml:/opt/flowforge-device/device.yml -p 1880:1880 flowforge/device-agent:latest flowforge-device-agent -v
docker run -v /path/to/device.yml:/opt/flowfuse-device/device.yml -p 1880:1880 flowfuse/device-agent:latest flowfuse-device-agent -v
```
27 changes: 25 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const ConfigLoader = require('./lib/config')
const webServer = new WebServer()

function main (testOptions) {
const pkg = require('./package.json')
if (pkg.name === '@flowforge/flowforge-device-agent') {
console.log(`
**************************************************************************
* The FlowFuse Device Agent is moving to '@flowfuse/device-agent' on npm *
* and 'flowfuse/device-agent' on DockerHub. Please upgrade to the new *
* packages to ensure you continue to receive updates. *
* See https://flowfuse.com/docs/device-agent/install/ for details *
**************************************************************************
`)
}

let options

try {
Expand All @@ -27,14 +39,25 @@ function main (testOptions) {
quit()
}
if (options.version) {
console.log(require('./package.json').version)
console.log(pkg.version)
quit()
}
if (options.help) {
console.log(require('./lib/cli/usage').usage())
quit()
}

if (options.dir === '') {
// No dir has been explicitly set, so we need to set the default.
// 1. Use `/opt/flowforge-device` if it exists
// 2. Otherwise use `/opt/flowfuse-device`
if (fs.existsSync('/opt/flowforge-device')) {
options.dir = '/opt/flowforge-device'
} else {
options.dir = '/opt/flowfuse-device'
}
}

if (!path.isAbsolute(options.dir)) {
options.dir = path.join(process.cwd(), options.dir)
}
Expand All @@ -48,7 +71,7 @@ function main (testOptions) {
}
} catch (err) {
const quitMsg = `Cannot create dir '${options.dir}'.
Please ensure the parent directory is writable, or set a different path with -d`
Please ensure the parent directory is writable, or set a different path with -d`
quit(quitMsg, 20) // Exit Code 20 - Invalid dir
// REF: https://slg.ddnss.de/list-of-common-exit-codes-for-gnu-linux/
return
Expand Down
6 changes: 4 additions & 2 deletions lib/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ module.exports = [
},
{
name: 'dir',
description: 'Where the agent should store its state. Default: {underline /opt/flowforge-device}',
description: 'Where the agent should store its state. Default: {underline /opt/flowfuse-device}',
alias: 'd',
type: String,
defaultValue: '/opt/flowforge-device',
// Set default to blank so we can distinguish between it being left as
// default, and a user setting it explicitly via -d
defaultValue: '',
typeLabel: '{underline dir}',
group: 'main'
},
Expand Down
Loading

0 comments on commit 47ca4c9

Please sign in to comment.