diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..12bf9f4 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,84 @@ +labels: + hostname: "macmini7" +clone: + git: + image: woodpeckerci/plugin-git + settings: + partial: false + depth: 1 +steps: + build-staging: + name: build-staging + image: woodpeckerci/plugin-docker-buildx + secrets: [REGISTRY_USER, REGISTRY_PASSWORD] + volumes: + - /var/run/docker.sock:/var/run/docker.sock + commands: + - echo "Building application for staging branch" + - echo "$${REGISTRY_PASSWORD}" | docker login -u "$${REGISTRY_USER}" --password-stdin git.nixc.us + - echo compose build + - docker compose -f docker-compose.staging.yml build + when: + - branch: main + - event: push + - path: + include: [ 'stack.production.yml', 'stack.staging.yml', 'docker-compose.staging.yml', 'docker-compose.production.yml', 'Dockerfile', '*.tests.ts' ] + + deploy-new: + name: deploy-new + when: + - branch: main + - path: + include: [ 'stack.production.yml', 'stack.staging.yml', 'docker-compose.staging.yml', 'docker-compose.production.yml', 'Dockerfile', '*.tests.ts' ] + image: woodpeckerci/plugin-docker-buildx + secrets: [REGISTRY_USER, REGISTRY_PASSWORD] + volumes: + - /var/run/docker.sock:/var/run/docker.sock + commands: + - echo "$${REGISTRY_PASSWORD}" | docker login -u "$${REGISTRY_USER}" --password-stdin git.nixc.us + - echo compose push + - docker compose -f docker-compose.staging.yml push + + cleanup-staging: + name: cleanup-staging + when: + - branch: main + - path: + include: [ 'stack.production.yml', 'stack.staging.yml', 'docker-compose.staging.yml', 'docker-compose.production.yml', 'Dockerfile', '*.tests.ts' ] + image: woodpeckerci/plugin-docker-buildx + secrets: [REGISTRY_USER, REGISTRY_PASSWORD] + volumes: + - /var/run/docker.sock:/var/run/docker.sock + commands: + - docker compose -f docker-compose.staging.yml down + - docker compose -f docker-compose.staging.yml rm -f + + build-build-push-production: + name: build-build-push-production + image: woodpeckerci/plugin-docker-buildx + secrets: [REGISTRY_USER, REGISTRY_PASSWORD] + volumes: + - /var/run/docker.sock:/var/run/docker.sock + commands: + - echo "Building application for staging branch" + - echo "$${REGISTRY_PASSWORD}" | docker login -u "$${REGISTRY_USER}" --password-stdin git.nixc.us + - echo compose build + - docker compose -f docker-compose.production.yml build + - docker compose -f docker-compose.production.yml push + when: + - branch: production + - event: push + - path: + include: [ 'stack.production.yml', 'stack.staging.yml', 'docker-compose.staging.yml', 'docker-compose.production.yml', 'Dockerfile', '*.tests.ts' ] + + deploy-production: + name: deploy-production + image: woodpeckerci/plugin-docker-buildx + secrets: [REGISTRY_USER, REGISTRY_PASSWORD] + volumes: + - /var/run/docker.sock:/var/run/docker.sock + commands: + - echo "$${REGISTRY_PASSWORD}" | docker login -u "$${REGISTRY_USER}" --password-stdin git.nixc.us + when: + - branch: production + - event: push \ No newline at end of file diff --git a/README.md b/README.md index 4b0f932..a65f614 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,63 @@ -# UptimeRobot to Kuma migration +# UptimeRobot to Kuma Migration -We migrated from UptimeRobot to UptimeKuma, but there was no fast way to achieve this, so -we wrote our own small migration helper. +We needed a fast and easy way to migrate from UptimeRobot to UptimeKuma, so we created this migration helper. It leverages Docker Compose to simplify the entire process. -## Getting started -Copy the `.env.sample` as `.env` and enter your UptimeRobot API key. +## WARRANTY VOID WARNING +This repository comes entirely without support if something on the docker layer doesn't work and you know how to reach out to me please feel free and we could tweak some stuff but the nature of Docker is to unify environments so that support is effectively unnecessary if you're doing your docker layer correctly. This repository uses source code from a publically contributed tool written by github user @sandstorm via https://github.com/sandstorm/uptime-robot-to-kuma-helper and I offer no assurance of continued support from them but this allegedly worked the year they supplied this code and if someone wants to fork this and maintain it I would hope that they post about it in this thread as the UptimeKuma people don't seem to have any interest or resources available for interoperability. https://github.com/louislam/uptime-kuma/issues/1190 -For testing, you can simply start UptimeKuma via Docker: +## Prerequisites -```shell -docker run --rm -p 3001:3001 --name uptime-kuma louislam/uptime-kuma:1 -``` +* Docker and Docker Compose installed. +* A copy of your UptimeKuma data directory (for safety). -Ensure you finished the initial setup (simply open [localhost:3001](localhost:3001) in your browser) and -updated the credentials in the `.env` file. +## Migration Steps -To start the migration run: +1. **Clone the Repository:** + ```bash + git clone https://github.com/Nixius/UptimeRobot-Migrator.git # Replace if your project is elsewhere + cd uptimerobot-migrator + ``` +Alternatively, you can probably copy this repository docker-compose.yml somewhere useful in your case. -```bash -# copy all your UptimeRobot monitors to your Kuma installation -yarn copy-monitors +2. **Environment Configuration:** + * Edit the docker-compose.yml + * Enter your UptimeRobot API key. + * Provide your Kuma URL, username, and password. -# disable all UptimeRobot monitors -yarn disable-uptime-robot +3. **Place UptimeKuma Data (if migrating to an existing instance):** + * Place a copy of your UptimeKuma data into a directory named `data` next to the `docker-compose.yml` file. -# delete all your monitors from UptimeRobot -# DANGER!!! This is can not be undone -yarn delete-uptime-robot -``` +4. **Execute the Migration:** + * Run the following command to start the temporary uptime kuma instance we include in the background to copy your monitors to: + ```bash + docker-compose up -d kuma-migration + ``` + * Ensure that uptime Kuma is online by navigating to it in your browser if you have this locally it should be located at http://localhost:3001/ and use the credentials you set in your original instance. + * Next you need to launch the migrator in the foreground. + ```bash + docker-compose up migrator + ``` + * Once the migrator has completed you must check your temporary uptime kuma instance we loaded up earlier and then if everything is copacetic you can do `docker-compose down && docker-compose rm` to clean up the mess. -## Production Migration -**Important Node:** This migration helper was writen specially for our use-case. So not all UptimeRobot -scenarios and features are implemented. So no garantie this will work 100% for you. + * Additionally, To perform other actions, modify the `docker-compose.yml` file: + * Change the `command` under the `migrator` service: + * `disable-uptime-robot` + * `delete-uptime-robot` (**Caution:** This action is irreversible) -**Pro Tipp:** Before migrating, create a default notification that will get used as default. +## Important Notes -## Architecture +* **Backup:** Always create a backup of your UptimeKuma data before running the migration. +* **Customization:** The helper was designed for our use case. You must modify it to fit your specific API key and credentials. +* **Default Notifications:** Consider creating a default notification in UptimeKuma beforehand. -### Fetching from UptimeRobot +## Disclaimer -This part was quite easy, because UptimeRobot got a good REST-API to fetch all monitors from +This tool aims to streamline the migration, but we cannot guarantee perfect results with every UptimeRobot configuration and Kuma setup. -### Creating the monitors in Kuma +**Key Improvements:** -This was the hard part. Currently, Kuma does not provide any form of API. In the first version of this migration -helper, I tried to hook into the websocket connection of the UI and create monitors that way. This was really instabile -and resulted in many non-deterministic errors. - -For this reason I switched to Playwright. This allows us the remote-control a browser, which will create -the monitors via the Kuma-UI. +* **Focus on `docker-compose.yml`:** Instructions prioritize the ease of using the provided compose file. +* **Clarity:** The outline of the prerequisites and steps emphasizes that the migration runs with a single command. +* **UptimeKuma Data:** Includes guidance on handling data for existing Kuma instances. diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.production.yml b/docker-compose.production.yml new file mode 100644 index 0000000..503a769 --- /dev/null +++ b/docker-compose.production.yml @@ -0,0 +1,8 @@ +version: '3.8' + +services: + migrator: + build: + context: docker/migrator + dockerfile: Dockerfile.production + image: git.nixc.us/nixius/uptimerobot-migrator:production \ No newline at end of file diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml new file mode 100644 index 0000000..653845c --- /dev/null +++ b/docker-compose.staging.yml @@ -0,0 +1,8 @@ +version: '3.8' + +services: + migrator: + build: + context: docker/migrator + dockerfile: Dockerfile + image: git.nixc.us/nixius/uptimerobot-migrator:staging \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c980072 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.8' + +services: + kuma-migration: + image: louislam/uptime-kuma:1 + ports: + - '3001:3001' + networks: + - default + ## make sure you run this on a copy of your uptime kuma data not your live one. + volumes: + - ./data:/app/data + + migrator: + build: . + image: git.nixc.us/nixius/uptimerobot-migrator:production + environment: + UPTIME_ROBOT_API_KEY: "xxxxxxxxxxxxxxxxxxxxxxxxxxx" # change this for sure and don't share it. + KUMA_URL: "http://kuma-migration:3001" # probably don't change this + KUMA_USERNAME: "admin" # change this + KUMA_PASSWORD: "password2" # don't share this and change it + depends_on: + - kuma-migration + networks: + - default + restart: "no" + command: ["copy-monitors"] # replace with the different task names as needed options are copy-monitors, disable-uptime-robot, delete-uptime-robot \ No newline at end of file diff --git a/.env.sample b/docker/migrator/.env.sample similarity index 100% rename from .env.sample rename to docker/migrator/.env.sample diff --git a/.gitignore b/docker/migrator/.gitignore similarity index 100% rename from .gitignore rename to docker/migrator/.gitignore diff --git a/.nvmrc b/docker/migrator/.nvmrc similarity index 100% rename from .nvmrc rename to docker/migrator/.nvmrc diff --git a/docker/migrator/Dockerfile b/docker/migrator/Dockerfile new file mode 100644 index 0000000..10ffccb --- /dev/null +++ b/docker/migrator/Dockerfile @@ -0,0 +1,6 @@ +FROM node:18.13.0 +WORKDIR /usr/src/app +COPY . . +RUN yarn install && chmod +x entrypoint.sh +EXPOSE 3000 +ENTRYPOINT ['/entrypoint.sh'] diff --git a/docker/migrator/Dockerfile.production b/docker/migrator/Dockerfile.production new file mode 100644 index 0000000..4771bfc --- /dev/null +++ b/docker/migrator/Dockerfile.production @@ -0,0 +1 @@ +FROM git.nixc.us/nixius/uptimerobot-migrator:staging \ No newline at end of file diff --git a/docker/migrator/entrypoint.sh b/docker/migrator/entrypoint.sh new file mode 100644 index 0000000..1025293 --- /dev/null +++ b/docker/migrator/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +case "$1" in + "copy-monitors") + yarn copy-monitors + ;; + "disable-uptime-robot") + yarn disable-uptime-robot + ;; + "delete-uptime-robot") + echo "DANGER!!: This action can not be undone" + read -p "Are you sure you want to delete all UptimeRobot monitors? (yes/no): " confirm + if [[ $confirm == "yes" ]]; then + yarn delete-uptime-robot + else + echo "Deletion canceled." + fi + ;; + *) + echo "Usage: $0 {copy-monitors | disable-uptime-robot | delete-uptime-robot}" + exit 1 + ;; +esac \ No newline at end of file diff --git a/package.json b/docker/migrator/package.json similarity index 100% rename from package.json rename to docker/migrator/package.json diff --git a/src/index.ts b/docker/migrator/src/index.ts similarity index 100% rename from src/index.ts rename to docker/migrator/src/index.ts diff --git a/src/types.ts b/docker/migrator/src/types.ts similarity index 100% rename from src/types.ts rename to docker/migrator/src/types.ts diff --git a/tsconfig.json b/docker/migrator/tsconfig.json similarity index 100% rename from tsconfig.json rename to docker/migrator/tsconfig.json diff --git a/yarn.lock b/docker/migrator/yarn.lock similarity index 100% rename from yarn.lock rename to docker/migrator/yarn.lock