manual-using-extra-docker-in-docker #64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: manual-using-extra-docker-in-docker | |
on: | |
workflow_dispatch: | |
inputs: | |
rosver: | |
description: 'RouterOS Version' | |
required: true | |
default: "7.12.1" | |
start_path: | |
description: 'Starting path (space seperated)' | |
required: false | |
jobs: | |
job-using-extra-docker-in-docker: | |
runs-on: ubuntu-latest | |
env: | |
URLBASE: http://localhost:9180/rest | |
BASICAUTH: "admin:" | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v1 | |
- name: Install Docker Compose | |
run: sudo apt install docker-compose | |
- name: Allow `git` | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Run Docker Compose | |
run: | | |
ROUTEROS_VERSION=${{ github.event.inputs.rosver }} | |
ROUTEROS_IMAGE="chr-${ROUTEROS_VERSION}.vdi" | |
ROUTEROS_PATH="https://cdn.mikrotik.com/routeros/${ROUTEROS_VERSION}/${ROUTEROS_IMAGE}.zip" | |
echo $ROUTEROS_VERSION | |
echo $ROUTEROS_IMAGE | |
echo $ROUTEROS_PATH | |
echo `which docker-compose` | |
echo "version: '3' | |
services: | |
routeros: | |
build: | |
context: . | |
dockerfile: ./Dockerfile.chr-qemu | |
args: | |
ARG_ROUTEROS_VERSION: "${ROUTEROS_VERSION}" | |
restart: unless-stopped | |
cap_add: | |
- NET_ADMIN | |
devices: | |
- /dev/net/tun | |
- /dev/kvm | |
ports: | |
- '9180:80' | |
- '9122:22'" > docker-compose.yml | |
docker-compose up -d | |
- name: Wait For `curl` to CHR | |
run: | | |
echo "Waiting for the HTTP server to start..." | |
for i in {1..1000}; do | |
if curl -m 5 -S --fail http://localhost:9180/; then | |
echo "Server is up!" | |
exit 0 | |
else | |
echo "Server not ready yet. Retrying in 10 seconds..." | |
sleep 10 | |
fi | |
done | |
echo "Server did not start within expected time." | |
exit 1 | |
- name: Test REST API to CHR with curl | |
run: curl -c 30 -S --fail http://admin@localhost:9180/rest/ip/address | |
- name: Copy extra-packages packages to CHR | |
run: | | |
mkdir extra | |
cd extra | |
wget https://download.mikrotik.com/routeros/${{ github.event.inputs.rosver }}/all_packages-x86-${{ github.event.inputs.rosver }}.zip | |
unzip all_packages*.zip | |
rm all_packages*.zip | |
cd .. | |
scp -o 'StrictHostKeyChecking no' -P 9122 extra/* admin@localhost:/ | |
- name: Reboot CHR to use extra-packages | |
run: | | |
# curl -X POST http://admin@localhost:9180/rest/system/reboot --header "Content-Type: application/json" | |
ssh -p 9122 admin@localhost /system/reboot || true | |
- name: Setup Bun Runtime | |
uses: oven-sh/setup-bun@v1 | |
with: | |
bun-version: 'latest' | |
- name: Setup NodeJS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: 2nd Wait For `curl` to CHR | |
run: | | |
echo "Waiting for the HTTP server to start..." | |
for i in {1..1000}; do | |
if curl -m 5 -S --fail http://localhost:9180/; then | |
echo "Server is up!" | |
exit 0 | |
else | |
echo "Server not ready yet. Retrying in 10 seconds..." | |
sleep 10 | |
fi | |
done | |
echo "Server did not start within expected time." | |
exit 1 | |
- name: Get let of pacakges from REST API to CHR with curl | |
run: curl -c 30 -S --fail http://admin@localhost:9180/rest/system/package | jq '.[] | .name' | |
- name: Test Bun Connection to RouterOS | |
id: connection-check | |
run: | | |
BUNROSVER=$(bun rest2raml.js --version) | |
echo "rosver=$BUNROSVER" | xargs >> "$GITHUB_OUTPUT" | |
- name: Run RAML Generator Code with Bun | |
run: | | |
bun install js-yaml raml2html raml2html-slate-theme | |
bun rest2raml.js ${{ github.event.inputs.start_path }} | |
./node_modules/.bin/raml2html -v --theme raml2html-slate-theme ros-rest*.raml > index.html | |
- name: Validate RAML 1.0 using webapi-parse library | |
run: | | |
npm install webapi-parser | |
node validraml.cjs ros-rest*.raml | |
- name: Convert RAML 1.0 to OAS 2.0 using webapi-parse library | |
run: | | |
npm install webapi-parser | |
node raml2oas.cjs ros-rest*.raml | |
- name: Move Built File to /docs | |
id: publish-to-docs | |
run: | | |
echo ${{ steps.connection-check.outputs.rosver }} | |
echo $ROS_FILTER | |
ROS_FILTER=$(echo ${{ github.event.inputs.start_path }} | tr ' ' '+') | |
DOCS_PATH=docs/${{ steps.connection-check.outputs.rosver }}/extra/$ROS_FILTER | |
echo $DOCS_PATH | |
mkdir -p $DOCS_PATH/docs | |
cp index.html $DOCS_PATH/docs | |
cp ros-rest*.raml $DOCS_PATH/schema.raml | |
cp ros-inspect*.json $DOCS_PATH/inspect.json | |
cp ros-oas2*.json $DOCS_PATH/oas2.json | |
# cp ros-oas3*.json $DOCS_PATH/oas3.json | |
echo "subpath=$ROS_FILTER" >> $GITHUB_OUTPUT | |
ls -r | |
- name: Commit and push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git status | |
git pull | |
git add docs/${{ steps.connection-check.outputs.rosver }}/* | |
git commit -m "Publish ${{ steps.connection-check.outputs.rosver }} ${{ steps.publish-to-docs.outputs.subpath }} [${{ github.workflow }}]" | |
git push origin main | |
- name: Save Build Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-results | |
path: | | |
ros-rest*.raml | |
ros-inspect*.json | |
index.html | |
- name: Cleanup Running Docker | |
run: docker-compose down |