From 7bb1fe3c754318ec2f78d286b6735ccea89eee51 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sun, 4 Feb 2024 14:06:56 -0700 Subject: [PATCH 01/13] Add action to help review github action. --- .github/workflows/lint.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..dbb13a9 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,14 @@ +name: Lint github-action + +on: [ 'pull_request' ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Lint + uses: docker://rhysd/actionlint:1.6.26 + with: + args: -color From 9fcaa9af07b9f0c426c8053ec4ea644dfd4e5d97 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sun, 4 Feb 2024 14:08:04 -0700 Subject: [PATCH 02/13] Add github action ensure generated image work. This check that the test image answer to the REST API with Mikrotik platform in it. --- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a489773 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: "Continuous Integration Tests" + +on: + push: + pull_request: + workflow_dispatch: + workflow_call: + +jobs: + test: + name: "Build & Test images" + runs-on: "ubuntu-latest" + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download docker-compose when using act + if: env.ACT + run: | + sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + + - name: Test with Docker + run: | + # start the container + docker-compose up --build -d routeros-local + # wait for the container to start + sleep 5 + DOCKERID=$(docker ps --format '{{.ID}}.{{.Names}}.{{.Image}}'|grep evilfreelancer/docker-routeros|cut -f 1 -d '.') + echo "Watching $DOCKERID for Mikrotik login..." + while true + do + if docker logs "$DOCKERID" 2>&1|grep 'MikroTik' + then + break + fi + echo "Not found yet, sleeping..." + sleep 5 + done + # display logs + echo "Container logs:" + docker logs "$DOCKERID" + # download resource and check platform is Mikrotik + curl --retry 12 --retry-all-errors -k -u admin: http://127.0.0.1:7777/rest/system/resource | jq .platform |grep -i mikrotik + + - name: Stop container + run: docker-compose down From ec169403152da71f72c2a7e630663af8ab503ee7 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sun, 4 Feb 2024 14:56:16 -0700 Subject: [PATCH 03/13] Add a github action to automatically generate a PR for new CHR release. --- .github/workflows/pr.yml | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..60bd332 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,47 @@ +name: "Check for update on Mikrotik website and generate a PR if necessary" + +on: + workflow_dispatch: + schedule: + - cron: "0 4 * * *" + +jobs: + routeros: + name: "Build & Test images" + runs-on: "ubuntu-latest" + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: '1' + + - name: Check new release + id: check_release + run: | + LAST_MIKROTIK_RELEASE=$(curl https://mikrotik.com/download/archive -o - 2>/dev/null | grep -o ' "$GITHUB_OUTPUT" + echo "new=true" >> "$GITHUB_OUTPUT" + else + echo "No new version found" + echo "new=false" >> "$GITHUB_OUTPUT" + fi + + - name: Edit Dockerfile + if: ${{ steps.check_release.outputs.new == 'true' }} + run: | + sed -r "s/(ROUTEROS_VERSION=\")(.*)(\")/\1${{ steps.check_release.outputs.release }}\3/g" -i Dockerfile + git diff + + - name: Create Pull Request + if: ${{ steps.check_release.outputs.new == 'true' && !env.ACT }} + uses: peter-evans/create-pull-request@v6 + with: + commit-message: "Update RouterOS version to ${{ steps.check_release.outputs.release }}" + committer: "GitHub Actions" + body: 'Created by Github action' + title: 'Update RouterOS version to ${{ steps.check_release.outputs.release }}' + branch: update-routeros From 75ebc85d1e1477f145351159fec0e52b68fa5a5a Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sun, 4 Feb 2024 14:56:55 -0700 Subject: [PATCH 04/13] Add a github action that automatically upload tag to docker. --- .github/workflows/cd.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..40826a3 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,34 @@ +name: "Build docker image and push to DockerHub when a tag is pushed" + +on: + workflow_dispatch: + push: + tags: + - "*" + +jobs: + build: + name: "Build images" + runs-on: "ubuntu-latest" + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Docker metadata from Git + id: meta + uses: docker/metadata-action@v5 + with: + images: evilfreelancer/docker-routeros + - name: Login to DockerHub + if: ${{ !env.ACT }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build with Docker + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ !env.ACT }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + \ No newline at end of file From 30e74bd33941f6dc001a96e7746f10340dfeb50c Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sun, 4 Feb 2024 14:57:44 -0700 Subject: [PATCH 05/13] Add a github action that automatically create tag on master. This action will add a tag matching ROUTEROS release once master pass the CI step after a push to master (can be the result of direct push, PR merge, ...). This tag being pushed will trigger the CD github action which will push the docker image that match this tag to docker hub. --- .github/workflows/tag.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..86650d0 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,36 @@ +name: "Tag master with new version of RouterOS when CI pass" + +on: + push: + branches: + - "master" + +permissions: + contents: write + pull-requests: read + +jobs: + call_test: + uses: EvilFreelancer/docker-routeros/.github/workflows/ci.yml@master + + tag: + name: "Add a tag to git" + runs-on: "ubuntu-latest" + needs: call_test + if: always() && needs.call_test.result == 'success' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: '0' + + - name: Add new tag on git + run: | + NEW_TAG=$(grep 'ROUTEROS_VERSION="' Dockerfile |cut -d '"' -f 2) + git config user.name 'GitHub Actions' + git config user.email 'github-actions@users.noreply.github.com' + git tag "$NEW_TAG" + + - name: Push new tag to git + if: ${{ !env.ACT }} + run: git push origin "$NEW_TAG" From 7c5f724e252dcdfaaa318fe7702ab182c9c0eda2 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sat, 3 Feb 2024 21:29:36 -0700 Subject: [PATCH 06/13] Update to more recent Alpine. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5f650a2..1d05d5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.11 +FROM alpine:3.19.1 # For access via VNC EXPOSE 5900 From 9ce84b8a7ae23e76c770a8ab887d18f9d34f7a54 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sat, 3 Feb 2024 21:32:13 -0700 Subject: [PATCH 07/13] Rename to ROUTEROS_VERSION. --- Dockerfile | 6 +++--- cron.sh | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1d05d5e..12c9a3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,9 @@ RUN set -xe \ bridge-utils iptables jq bash python3 # Environments which may be change -ENV ROUTEROS_VERSON="7.1beta6" -ENV ROUTEROS_IMAGE="chr-$ROUTEROS_VERSON.vdi" -ENV ROUTEROS_PATH="https://download.mikrotik.com/routeros/$ROUTEROS_VERSON/$ROUTEROS_IMAGE" +ENV ROUTEROS_VERSION="7.1beta6" +ENV ROUTEROS_IMAGE="chr-${ROUTEROS_VERSION}.vdi" +ENV ROUTEROS_PATH="https://download.mikrotik.com/routeros/${ROUTEROS_VERSION}/${ROUTEROS_IMAGE}" # Download VDI image from remote site RUN wget "$ROUTEROS_PATH" -O "/routeros/$ROUTEROS_IMAGE" diff --git a/cron.sh b/cron.sh index 0864392..ab4d883 100755 --- a/cron.sh +++ b/cron.sh @@ -36,11 +36,10 @@ getTarballs | while read line; do if [ "x$(checkTag "$tag")" == "x" ] then - url="https://download.mikrotik.com/routeros/$tag/chr-$tag.vdi" if curl --output /dev/null --silent --head --fail "$url"; then echo ">>> URL exists: $url" - sed -r "s/(ROUTEROS_VERSON=\")(.*)(\")/\1$tag\3/g" -i Dockerfile + sed -r "s/(ROUTEROS_VERSION=\")(.*)(\")/\1$tag\3/g" -i Dockerfile git commit -m "Release of RouterOS changed to $tag" -a git push git tag "$tag" From c057b0c19510bf7e8a941ecdc15d6cc3e421b8d8 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sat, 3 Feb 2024 21:33:20 -0700 Subject: [PATCH 08/13] Rename docker-compose.dist.yml to more practical name. --- .gitignore | 1 - docker-compose.dist.yml | 32 ------------------------ docker-compose.yml | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 33 deletions(-) delete mode 100644 docker-compose.dist.yml create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 42efebe..8a7c9d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /.idea/ /*.vdi -/docker-compose.yml diff --git a/docker-compose.dist.yml b/docker-compose.dist.yml deleted file mode 100644 index 2f20fb6..0000000 --- a/docker-compose.dist.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: "3" - -services: - - routeros-6-42: - image: evilfreelancer/docker-routeros:6.42.12 - restart: unless-stopped - cap_add: - - NET_ADMIN - devices: - - /dev/net/tun - ports: - - "12222:22" - - "12223:23" - - "18728:8728" - - "18729:8729" - - routeros-6-47: - image: evilfreelancer/docker-routeros:latest - restart: unless-stopped - cap_add: - - NET_ADMIN - devices: - - /dev/net/tun - ports: - - "22222:22" - - "22223:23" - - "7777:80" - - "8728:8728" - - "8729:8729" - - "28728:8728" - - "28729:8729" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..83031c6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,54 @@ +version: "3" + +services: + routeros-6-48: + image: evilfreelancer/docker-routeros:6.48.4 + restart: unless-stopped + cap_add: + - NET_ADMIN + devices: + - /dev/net/tun + - /dev/kvm + ports: + - "12222:22" + - "12223:23" + - "18728:8728" + - "18729:8729" + + routeros-latest: + image: evilfreelancer/docker-routeros:latest + restart: unless-stopped + cap_add: + - NET_ADMIN + devices: + - /dev/net/tun + - /dev/kvm + ports: + - "22222:22" + - "22223:23" + - "7777:80" + - "8728:8728" + - "8729:8729" + - "28728:8728" + - "28729:8729" + + routeros-local: + image: evilfreelancer/docker-routeros:latest + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + cap_add: + - NET_ADMIN + devices: + - /dev/net/tun + - /dev/kvm + ports: + - "22222:22" + - "22223:23" + - "7777:80" + - "8728:8728" + - "8729:8729" + - "28728:8728" + - "28729:8729" + - "5900:5900" From 1e83bfa67e3c580aca8314f52f35c74e23a0ff00 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sat, 3 Feb 2024 21:34:25 -0700 Subject: [PATCH 09/13] Add KVM support. --- scripts/entrypoint.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index c8e6afa..7240d84 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -36,6 +36,20 @@ prepare_intf $default_dev1 $QEMU_BRIDGE_ETH1 # Finally, start our DHCPD server udhcpd -I $DUMMY_DHCPD_IP -f $DHCPD_CONF_FILE & +CPU_FEATURES="" +KVM_OPTS="" +if [ -e /dev/kvm ]; then + if grep -q -e vmx -e svm /proc/cpuinfo; then + echo "Enabling KVM" + CPU_FEATURES=",kvm=on" + KVM_OPTS="-machine accel=kvm -enable-kvm" + fi +fi + +if [ "$CPU_FEATURES" = "" ]; then + echo "KVM not available, running in emulation mode. This will be slow." +fi + # And run the VM! A brief explanation of the options here: # -enable-kvm: Use KVM for this VM (much faster for our case). # -nographic: disable SDL graphics. @@ -44,10 +58,12 @@ udhcpd -I $DUMMY_DHCPD_IP -f $DHCPD_CONF_FILE & # -drive: The VM image we're booting. # mac: Set up your own interfaces mac addresses here, cause from winbox you can not change these later. exec qemu-system-x86_64 \ - -nographic -serial mon:stdio \ - -vnc 0.0.0.0:0 \ + -serial mon:stdio \ + -nographic \ -m 512 \ -smp 4,sockets=1,cores=4,threads=1 \ + -cpu host$CPU_FEATURES \ + $KVM_OPTS \ -nic tap,id=qemu1,mac=54:05:AB:CD:12:31,script=$QEMU_IFUP,downscript=$QEMU_IFDOWN \ "$@" \ -hda $ROUTEROS_IMAGE From a3e85227bd5348107eb5012a5e9dc8ee57ead189 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sun, 4 Feb 2024 15:06:03 -0700 Subject: [PATCH 10/13] Add last Mikrotik 6.49 release --- Dockerfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 12c9a3a..1eb7568 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,18 +11,20 @@ WORKDIR /routeros # Install dependencies RUN set -xe \ - && apk add --no-cache --update \ + && apk add --no-cache --update \ netcat-openbsd qemu-x86_64 qemu-system-x86_64 \ busybox-extras iproute2 iputils \ bridge-utils iptables jq bash python3 # Environments which may be change -ENV ROUTEROS_VERSION="7.1beta6" +ENV ROUTEROS_VERSION="6.49.12" ENV ROUTEROS_IMAGE="chr-${ROUTEROS_VERSION}.vdi" -ENV ROUTEROS_PATH="https://download.mikrotik.com/routeros/${ROUTEROS_VERSION}/${ROUTEROS_IMAGE}" +ENV ROUTEROS_PATH="https://download.mikrotik.com/routeros/${ROUTEROS_VERSION}/${ROUTEROS_IMAGE}.zip" # Download VDI image from remote site -RUN wget "$ROUTEROS_PATH" -O "/routeros/$ROUTEROS_IMAGE" +RUN wget "$ROUTEROS_PATH" -O "/routeros/${ROUTEROS_IMAGE}.zip" && \ + unzip "/routeros/${ROUTEROS_IMAGE}.zip" -d "/routeros" && \ + rm -f "/routeros/${ROUTEROS_IMAGE}.zip" # Copy script to routeros folder ADD ["./scripts", "/routeros"] From 2a375306560f0a817007a43160b391b6462abd62 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sat, 3 Feb 2024 21:36:16 -0700 Subject: [PATCH 11/13] Update to almost latest version. I am not picking the latest version to give a chance to the autoamtion to kick in and generate a PR shorlty after merging this PR. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1eb7568..d7319fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN set -xe \ bridge-utils iptables jq bash python3 # Environments which may be change -ENV ROUTEROS_VERSION="6.49.12" +ENV ROUTEROS_VERSION="7.13.2" ENV ROUTEROS_IMAGE="chr-${ROUTEROS_VERSION}.vdi" ENV ROUTEROS_PATH="https://download.mikrotik.com/routeros/${ROUTEROS_VERSION}/${ROUTEROS_IMAGE}.zip" From 9ad7cbfa3eb4e7ed446848213b155c7164913825 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Sun, 4 Feb 2024 15:11:43 -0700 Subject: [PATCH 12/13] Enable dependabot. --- .github/dependabot.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0fce7be --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "docker" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" From de946d84b004e70ef9c034c4293b024dbb6ad64a Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Wed, 7 Feb 2024 21:25:07 -0700 Subject: [PATCH 13/13] Rename docker-compose.yml to docker-compose.dist.yml. --- .github/workflows/ci.yml | 4 ++-- .gitignore | 1 + docker-compose.yml => docker-compose.dist.yml | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename docker-compose.yml => docker-compose.dist.yml (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a489773..8d069bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - name: Test with Docker run: | # start the container - docker-compose up --build -d routeros-local + docker-compose -f docker-compose.dist.yml up --build -d routeros-local # wait for the container to start sleep 5 DOCKERID=$(docker ps --format '{{.ID}}.{{.Names}}.{{.Image}}'|grep evilfreelancer/docker-routeros|cut -f 1 -d '.') @@ -44,4 +44,4 @@ jobs: curl --retry 12 --retry-all-errors -k -u admin: http://127.0.0.1:7777/rest/system/resource | jq .platform |grep -i mikrotik - name: Stop container - run: docker-compose down + run: docker-compose -f docker-compose.dist.yml down diff --git a/.gitignore b/.gitignore index 8a7c9d3..1043c31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea/ /*.vdi +/docker-compose.dist.yml \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.dist.yml similarity index 100% rename from docker-compose.yml rename to docker-compose.dist.yml