Skip to content

Commit

Permalink
Merge pull request #1 from tago-io/feat/mqttRelayPrototype#SRV-534
Browse files Browse the repository at this point in the history
Add bridge and API server support
  • Loading branch information
vitorfdl committed Jun 17, 2024
2 parents 5a2f16a + 2530c1a commit 5071110
Show file tree
Hide file tree
Showing 25 changed files with 4,035 additions and 548 deletions.
10 changes: 10 additions & 0 deletions .github/macos-build-entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
</dict>
</plist>
44 changes: 44 additions & 0 deletions .github/workflows/build-alpine-arm64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build for alpine-arm64

on: workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the code
- name: Checkout the code
uses: actions/checkout@v1

# Setup Docker for cross platform build
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

# Setup Docker for cross platform build
- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v1

# Build docker image
- name: Run build
run: docker buildx build --load --platform linux/arm64 -f ./docker/Dockerfile.alpine-arm64 . -t tagocore-container

# Pull binary out of docker container
- name: Extract tagocore binary out of docker
run: docker cp $(docker create tagocore-container):/usr/src/app/__build__binary__/tagocore ./tagocore

# Set binary as executable
- name: Chmod
run: chmod +x ./tagocore

# Zip the binary
- name: Generate tar.gz
run: tar cvf - tagocore | gzip > ./tagocore-alpine-arm64.tar.gz

# Upload the zip file as an artifact
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: mqttrelay-alpine-arm64
path: ../tagocore.zip
44 changes: 44 additions & 0 deletions .github/workflows/build-alpine-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build for alpine-x64

on: workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the code
- name: Checkout the code
uses: actions/checkout@v1

# Setup Docker for cross platform build
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

# Setup Docker for cross platform build
- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v1

# Build docker image
- name: Run build
run: docker buildx build --load --platform linux/arm64 -f ./docker/Dockerfile.alpine-arm64 . -t tagocore-container

# Pull binary out of docker container
- name: Extract tagocore binary out of docker
run: docker cp $(docker create tagocore-container):/usr/src/app/__build__binary__/tagocore ./tagocore

# Set binary as executable
- name: Chmod
run: chmod +x ./tagocore

# Zip the binary
- name: Generate tar.gz
run: tar cvf - tagocore | gzip > ./tagocore-alpine-arm64.tar.gz

# Upload the zip file as an artifact
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: mqttrelay-alpine-arm64
path: ../tagocore.zip
31 changes: 31 additions & 0 deletions .github/workflows/build-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy to DockerHub

on:
workflow_dispatch:
inputs:
version:
description: "Version"
required: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v1

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and deploy images
run: bash dockerhub.sh ${{ github.event.inputs.version }}
75 changes: 75 additions & 0 deletions .github/workflows/build-macos-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build for mac-x64

on: workflow_dispatch

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: macos-11

steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
run: |
rustup update --no-self-update stable
rustup component add --toolchain stable rustfmt
rustup default stable
- name: Create .env file
run: |
echo "SERVER_SSL_CA=${{ secrets.SERVER_SSL_CA }}" >> .env
echo "SERVER_SSL_CERT=${{ secrets.SERVER_SSL_CERT }}" >> .env
echo "SERVER_SSL_KEY=${{ secrets.SERVER_SSL_KEY }}" >> .env
# Build the modules
- name: Build
run: cargo build --verbose --release

# Run tests
- name: Run tests
run: cargo test --verbose

# # Sign the executable
# - name: Codesign binary
# env:
# MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
# MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
# MACOS_FULL_IDENTITY: ${{ secrets.MACOS_FULL_IDENTITY }}
# run: |
# echo $MACOS_CERTIFICATE | openssl base64 -d -A > certificate.p12
# security create-keychain -p $MACOS_CERTIFICATE_PWD build.keychain
# security default-keychain -s build.keychain
# security unlock-keychain -p $MACOS_CERTIFICATE_PWD build.keychain
# security import certificate.p12 -k build.keychain -P $MACOS_CERTIFICATE_PWD -T /usr/bin/codesign
# security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CERTIFICATE_PWD build.keychain
# cd __build__binary__
# /usr/bin/codesign -f -s "$MACOS_FULL_IDENTITY" --entitlements ../.github/macos-build-entitlements.plist --options=runtime --timestamp ./mqttrelay
# zip ./mqttrelay.zip ./mqttrelay
# /usr/bin/codesign -f -s "$MACOS_FULL_IDENTITY" --options=runtime --timestamp ./mqttrelay.zip

# # Notarize app using xcrun altool
# - name: Notarize binary
# env:
# MACOS_DEVELOPER_EMAIL: ${{ secrets.MACOS_DEVELOPER_EMAIL }}
# MACOS_DEVELOPER_PWD: ${{ secrets.MACOS_DEVELOPER_PWD }}
# MACOS_BUNDLE_ID: ${{ secrets.MACOS_BUNDLE_ID }}
# MACOS_ASC_PROVIDER: ${{ secrets.MACOS_ASC_PROVIDER }}
# run: xcrun altool --notarize-app --primary-bundle-id "$MACOS_BUNDLE_ID" -u "$MACOS_DEVELOPER_EMAIL" -p "$MACOS_DEVELOPER_PWD" --asc-provider "$MACOS_ASC_PROVIDER" -f ./__build__binary__/mqttrelay.zip

# Zip the binary
- name: Generate tar.gz
run: |
cd target/release
tar cvf - tago-relay | gzip > ../tago-relay-mac-x64.tar.gz
# Upload the zip file as an artifact
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: tago-relay-macos-x64
path: target/tago-relay-mac-x64.tar.gz
47 changes: 47 additions & 0 deletions .github/workflows/build-win-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build for win-x64
on: workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest
environment: PROD

steps:
# Checkout the code
- name: Checkout the code
uses: actions/checkout@v1

# Install dependencies
- name: Install dependencies
run: npm install

# Build the modules
- name: Run build
run: npm run build

# Manually copy the bin file of sdk to the .bin folder to use the local copy of the sdk
- name: Override tcore-plugin .bin file
run: cd ./node_modules/.bin; ln -s ../../packages/tcore-sdk/build/Bin/Bin.js tcore-plugin; chmod +x tcore-plugin; cd ../../

# Pack Plugin Store, TagoIO Integration, and Local Filesystem into a .tcore file
- name: Pack built-in plugins
run: npm run pack

# Add the packed .tcore files to the /plugins folder
- name: Move built-in plugins to plugins folder
run: npm run plugin:add

# Generate the executable
- name: Generate executable
run: ./node_modules/.bin/pkg package.json -t node16-win-x64 --public-packages "*" --no-bytecode --public --compress Brotli

# Zip the executable
- name: Generate zip
run: cd __build__binary__; zip ../tagocore.zip ./tagocore.exe

# Upload the zip file as an artifact
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: mqttrelay-windows-x64
path: ../tagocore.zip
55 changes: 55 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Code Quality
on: push

env:
CARGO_TERM_COLOR: always
stage: prod

jobs:
build:
runs-on: ubuntu-latest
environment: PROD
env:
SERVER_SSL_CA: ${{ secrets.SERVER_SSL_CA }}
SERVER_SSL_CERT: ${{ secrets.SERVER_SSL_CERT }}
SERVER_SSL_KEY: ${{ secrets.SERVER_SSL_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Rust toolchain and components
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy

- name: Create empty .env file
run: touch .env

- name: Build
run: cargo build --verbose

- name: Test
run: cargo test --verbose

- name: Lint
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

- name: Format Check
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/target
.env
config.toml
*.pem
5 changes: 5 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# fn_call_width = 80
# max_width = 240
tab_spaces = 2
max_width = 120
hard_tabs = false
Loading

0 comments on commit 5071110

Please sign in to comment.