Skip to content

Commit

Permalink
Merge pull request #123 from TheLab-ms/refactor/tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ATechAdventurer authored Mar 6, 2024
2 parents 66205f6 + cf31bfe commit 43d6ff0
Show file tree
Hide file tree
Showing 39 changed files with 1,048 additions and 342 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
43 changes: 15 additions & 28 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ name: Publish Docker Image
# documentation.

on:
push:
branches:
- 'main'
workflow_dispatch:

env:
Expand Down Expand Up @@ -84,33 +87,17 @@ jobs:
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}

# Checkout the other repository
- name: Checkout TheLab-ms/gitops repository
uses: actions/checkout@v3
with:
repository: TheLab-ms/gitops
ref: main
path: gitops
token: ${{ secrets.ACCESS_TOKEN }}

# Update the TOML file
- name: Update TOML file
run: |
NEW_IMAGE="image = \\\"ghcr.io/thelab-ms/gliderbot@${{ steps.build-and-push.outputs.digest }}\\\""
awk -v new_image="$NEW_IMAGE" 'BEGIN {OFS=FS} /^image =/ {$0=new_image} {print}' gitops/containers/gliderbot/gliderbot.toml > gitops/containers/gliderbot/gliderbot.toml.tmp
mv gitops/containers/gliderbot/gliderbot.toml.tmp gitops/containers/gliderbot/gliderbot.toml
# Create a new branch and commit changes
- name: Create a new branch and commit changes, then PR
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build
container:
image: docker.io/bitnami/kubectl:1.29.0
steps:
- name: 'Patch Image'
run: |
cd gitops
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
UNIQUE_BRANCH_NAME=update-gliderbot-image-$(date +%Y%m%d%H%M%S)
git checkout -b $UNIQUE_BRANCH_NAME
git add -A
git commit -m "Update Gliderbot image"
git push origin $UNIQUE_BRANCH_NAME
gh pr create --base main --head $UNIQUE_BRANCH_NAME --title "Update Gliderbot image" --body "Automated PR to update the Gliderbot image."
echo $KUBE_CONFIG | base64 -d > kc.yaml
kubectl --kubeconfig kc.yaml set image deployment/gliderbot svc=$NEW_IMAGE
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
KUBE_CONFIG: ${{ secrets.KUBECONFIG }}
NEW_IMAGE: ${{ needs.push.outputs.tag }}
285 changes: 243 additions & 42 deletions .vscode/schemas/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://thelab.ms/schema/config.json",
"title": "TheLab.ms Config Schema",
"description": "TheLab.ms Config Schema",
"id": "https://thelab.ms/schema/config.json",
"title": "TheLab.ms Config",
"type": "object",
"properties": {
"autoResponse": {
Expand Down Expand Up @@ -66,55 +65,257 @@
},
"description": "The bot status message."
},
"printers": {
"tools": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the printer."
},
"address": {
"type": "string",
"format": "uri",
"description": "The IP address or Hostname of the printer."
},
"apiKey": {
"type": "string",
"description": "The API key for the printer."
},
"hasWebcam": {
"type": "boolean",
"default": true,
"description": "Whether the printer has a webcam."
},
"make": {
"type": "string",
"description": "The make of the printer."
"anyOf": [
{
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the tool."
},
"make": {
"type": "string",
"description": "The make of the tool."
},
"model": {
"type": "string",
"description": "The model of the tool."
},
"type": {
"type": "string",
"const": "3D Printer",
"description": "The type of the tool."
},
"color": {
"anyOf": [
{
"type": "string",
"enum": [
"Default",
"Aqua",
"DarkAqua",
"Green",
"DarkGreen",
"Blue",
"DarkBlue",
"Purple",
"DarkPurple",
"LuminousVividPink",
"DarkVividPink",
"Gold",
"DarkGold",
"Orange",
"DarkOrange",
"Red",
"DarkRed",
"Grey",
"DarkGrey",
"DarkerGrey",
"LightGrey",
"Navy",
"DarkNavy",
"Yellow",
"White",
"Greyple",
"Black",
"DarkButNotBlack",
"NotQuiteBlack",
"Blurple",
"Green",
"Yellow",
"Fuchsia",
"Red"
]
},
{
"type": "string",
"pattern": "^\\#"
}
],
"description": "The color of the tool."
},
"hasWebcam": {
"type": "boolean",
"default": false,
"description": "Whether the tool has a webcam."
},
"adapter": {
"type": "string",
"enum": [
"octoprint",
"prusa-link",
"bambu",
"home-assistant"
],
"description": "The adapter for the tool."
},
"hasRemainingTime": {
"type": "boolean",
"default": true,
"description": "Whether the tool has remaining time sensor."
},
"address": {
"type": "string",
"format": "uri",
"description": "The IP address or Hostname of the printer."
},
"apiKey": {
"type": "string",
"description": "The API key for the printer."
}
},
"required": [
"name",
"make",
"model",
"type",
"color",
"adapter",
"address",
"apiKey"
],
"additionalProperties": false
},
"model": {
"type": "string",
"description": "The model of the printer."
{
"type": "object",
"properties": {
"name": {
"$ref": "#/properties/tools/items/anyOf/0/properties/name"
},
"make": {
"type": "string",
"const": "Bambu Labs",
"description": "The make of the tool."
},
"model": {
"type": "string",
"description": "The model of the tool."
},
"type": {
"type": "string",
"const": "3D Printer",
"description": "The type of the tool."
},
"color": {
"$ref": "#/properties/tools/items/anyOf/0/properties/color"
},
"hasWebcam": {
"$ref": "#/properties/tools/items/anyOf/0/properties/hasWebcam"
},
"adapter": {
"$ref": "#/properties/tools/items/anyOf/0/properties/adapter"
},
"hasRemainingTime": {
"type": "boolean",
"default": true,
"description": "Whether the tool has remaining time sensor."
},
"homeAssistantEntity": {
"type": "string",
"pattern": "^sensor\\.",
"description": "The entity id of the printer in Home Assistant. Example: sensor.ender_3_pro_print_state"
},
"homeAssistantCameraEntity": {
"type": "string",
"description": "The entity id of the camera in Home Assistant."
},
"homeAssistantFinishTimeEntity": {
"type": "string",
"description": "The entity id of the remaining time."
}
},
"required": [
"name",
"make",
"model",
"type",
"color",
"adapter",
"homeAssistantEntity"
],
"additionalProperties": false
},
"color": {
"type": "string",
"description": "The color of the printer."
{
"type": "object",
"properties": {
"name": {
"$ref": "#/properties/tools/items/anyOf/0/properties/name"
},
"make": {
"type": "string",
"const": "Prusa",
"description": "The make of the tool."
},
"model": {
"type": "string",
"enum": [
"i3 MK2.5",
"i3 MK2.5S",
"i3 MK3",
"i3 MK3S",
"i3 MK3S+",
"MK3.5",
"MK3.9",
"MK4",
"Mini",
"Mini+",
"XL"
],
"description": "The model of the tool."
},
"type": {
"type": "string",
"const": "3D Printer",
"description": "The type of the tool."
},
"color": {
"$ref": "#/properties/tools/items/anyOf/0/properties/color"
},
"hasWebcam": {
"$ref": "#/properties/tools/items/anyOf/0/properties/hasWebcam"
},
"adapter": {
"$ref": "#/properties/tools/items/anyOf/0/properties/adapter"
},
"hasRemainingTime": {
"type": "boolean",
"default": true,
"description": "Whether the tool has remaining time sensor."
},
"address": {
"type": "string",
"format": "uri",
"description": "The IP address or Hostname of the printer."
},
"apiKey": {
"type": "string",
"description": "The API key for the printer."
}
},
"required": [
"name",
"make",
"model",
"type",
"color",
"adapter",
"address",
"apiKey"
],
"additionalProperties": false
}
},
"required": [
"name",
"address",
"apiKey"
],
"additionalProperties": false
]
},
"default": [],
"description": "List of printers."
"description": "List of tools."
},
"forceKeycloakName": {
"type": "boolean",
"default": false
}
}
},
"additionalProperties": false
}
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ COPY src ./src
RUN npm ci
RUN npm run build

RUN npm i -g pm2

CMD ["pm2-runtime", "start", "dist/index.js"]
CMD ["node", "dist/index.js"]
Loading

0 comments on commit 43d6ff0

Please sign in to comment.