diff --git a/.devcontainer/init-cmd.sh b/.devcontainer/init-cmd.sh index a0c3b916..1ff1547c 100755 --- a/.devcontainer/init-cmd.sh +++ b/.devcontainer/init-cmd.sh @@ -14,13 +14,20 @@ until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" sleep 1 done +# Install openssl +wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.1n-0+deb10u6_amd64.deb +sudo dpkg -i libssl1.1_1.1.1n-0+deb10u6_amd64.deb + # Check architecture and copy the corresponding file if it exists ARCH=$(uname -m) -if [ "$ARCH" = "x86_64" ] && [ -f "/workspaces/ztnodeid/build/linux_amd64/ztmkworld" ]; then - cp /workspaces/ztnodeid/build/linux_amd64/ztmkworld /usr/local/bin/ztmkworld -elif [ "$ARCH" = "aarch64" ] && [ -f "/workspaces/ztnodeid/build/linux_arm64/ztmkworld" ]; then - cp /workspaces/ztnodeid/build/linux_arm64/ztmkworld /usr/local/bin/ztmkworld +if [ "$ARCH" = "x86_64" ] && [ -f "/workspaces/bin/mkworld/build/linux_amd64/ztmkworld" ]; then + cp /workspaces/bin/mkworld/build/linux_amd64/ztmkworld /usr/local/bin/ztmkworld + cp /workspaces/bin/idtool/build/linux_amd64/zerotier-idtool /usr/local/bin/zerotier-idtool +elif [ "$ARCH" = "aarch64" ] && [ -f "/workspaces/bin/mkworld/build/linux_arm64/ztmkworld" ]; then + cp /workspaces/bin/mkworld/build/linux_arm64/ztmkworld /usr/local/bin/ztmkworld + cp /workspaces/bin/idtool/build/linux_arm64/zerotier-idtool /usr/local/bin/zerotier-idtool fi + chmod +x /usr/local/bin/ztmkworld # apply migrations to the database diff --git a/Dockerfile b/Dockerfile index 14aa6016..ca8f5b25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,16 +35,24 @@ RUN SKIP_ENV_VALIDATION=1 npm run build # Copy the ztmkworld binary based on the target platform architecture FROM base AS ztmkworld_builder ARG TARGETPLATFORM + WORKDIR /app -COPY ztnodeid/build/linux_amd64/ztmkworld ztmkworld_amd64 -COPY ztnodeid/build/linux_arm64/ztmkworld ztmkworld_arm64 -RUN \ - case "${TARGETPLATFORM}" in \ - "linux/amd64") cp ztmkworld_amd64 /usr/local/bin/ztmkworld ;; \ - "linux/arm64") cp ztmkworld_arm64 /usr/local/bin/ztmkworld ;; \ + +COPY bin/mkworld/build/linux_amd64/ztmkworld ztmkworld_amd64 +COPY bin/mkworld/build/linux_arm64/ztmkworld ztmkworld_arm64 +COPY bin/idtool/build/linux_amd64/zerotier-idtool zerotier-idtool_amd64 +COPY bin/idtool/build/linux_arm64/zerotier-idtool zerotier-idtool_arm64 + +RUN case "${TARGETPLATFORM}" in \ + "linux/amd64") \ + cp ztmkworld_amd64 /usr/local/bin/ztmkworld && \ + cp zerotier-idtool_amd64 /usr/local/bin/zerotier-idtool ;; \ + "linux/arm64") \ + cp ztmkworld_arm64 /usr/local/bin/ztmkworld && \ + cp zerotier-idtool_arm64 /usr/local/bin/zerotier-idtool ;; \ *) echo "Unsupported architecture" && exit 1 ;; \ esac && \ - chmod +x /usr/local/bin/ztmkworld + chmod +x /usr/local/bin/ztmkworld /usr/local/bin/zerotier-idtool # Production image, copy all the files and run next FROM $NODEJS_IMAGE AS runner @@ -65,7 +73,24 @@ ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -RUN apt update && apt install -y curl sudo postgresql-client && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +RUN apt update && apt install -y curl wget sudo postgresql-client && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Openssl 1.1.1n is required for the zerotier-idtool +RUN ARCH=$(dpkg --print-architecture) && \ + if [ "$ARCH" = "amd64" ]; then \ + wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.1n-0+deb10u6_amd64.deb; \ + dpkg -i libssl1.1_1.1.1n-0+deb10u6_amd64.deb; \ + rm libssl1.1_1.1.1n-0+deb10u6_amd64.deb; \ + elif [ "$ARCH" = "arm64" ]; then \ + wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.1n-0+deb10u6_arm64.deb; \ + dpkg -i libssl1.1_1.1.1n-0+deb10u6_arm64.deb; \ + rm libssl1.1_1.1.1n-0+deb10u6_arm64.deb; \ + else \ + echo "Unsupported architecture: $ARCH"; \ + exit 1; \ + fi + + # need to install these package for seeding the database RUN npm install @prisma/client @paralleldrive/cuid2 RUN npm install -g prisma ts-node @@ -82,6 +107,7 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma COPY --from=builder --chown=nextjs:nodejs /app/init-db.sh ./init-db.sh COPY --from=ztmkworld_builder /usr/local/bin/ztmkworld /usr/local/bin/ztmkworld +COPY --from=ztmkworld_builder /usr/local/bin/zerotier-idtool /usr/local/bin/zerotier-idtool # prepeare .env file for the init-db.sh script RUN touch .env && chown nextjs:nodejs .env diff --git a/bin/idtool/Dockerfile b/bin/idtool/Dockerfile new file mode 100644 index 00000000..095ab2d9 --- /dev/null +++ b/bin/idtool/Dockerfile @@ -0,0 +1,28 @@ +# syntax=docker/dockerfile:1 + +# Build stage +FROM --platform=$TARGETPLATFORM ubuntu:20.04 AS builder + +ARG TARGETPLATFORM +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + curl \ + gnupg \ + lsb-release \ + && rm -rf /var/lib/apt/lists/* + +# Add ZeroTier repository and install +RUN curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --dearmor > /usr/share/keyrings/zerotier-archive-keyring.gpg +RUN echo "deb [signed-by=/usr/share/keyrings/zerotier-archive-keyring.gpg] http://download.zerotier.com/debian/$(lsb_release -cs) $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/zerotier.list + +RUN apt-get update && apt-get install -y zerotier-one + +# Final stage +FROM scratch AS export-stage + +# Copy zerotier-idtool from the builder stage +COPY --from=builder /usr/sbin/zerotier-idtool . + +# Build command: +# docker buildx build --platform linux/amd64,linux/arm64 --target export-stage -o type=local,dest=./build . \ No newline at end of file diff --git a/bin/idtool/build/linux_amd64/zerotier-idtool b/bin/idtool/build/linux_amd64/zerotier-idtool new file mode 100755 index 00000000..b97e99c0 Binary files /dev/null and b/bin/idtool/build/linux_amd64/zerotier-idtool differ diff --git a/bin/idtool/build/linux_arm64/zerotier-idtool b/bin/idtool/build/linux_arm64/zerotier-idtool new file mode 100755 index 00000000..85677c76 Binary files /dev/null and b/bin/idtool/build/linux_arm64/zerotier-idtool differ diff --git a/ztnodeid/Dockerfile b/bin/mkworld/Dockerfile similarity index 100% rename from ztnodeid/Dockerfile rename to bin/mkworld/Dockerfile diff --git a/ztnodeid/assets/mkworld.config.json b/bin/mkworld/assets/mkworld.config.json similarity index 100% rename from ztnodeid/assets/mkworld.config.json rename to bin/mkworld/assets/mkworld.config.json diff --git a/ztnodeid/build/freebsd_amd64/ztmkworld b/bin/mkworld/build/freebsd_amd64/ztmkworld similarity index 100% rename from ztnodeid/build/freebsd_amd64/ztmkworld rename to bin/mkworld/build/freebsd_amd64/ztmkworld diff --git a/ztnodeid/build/linux_amd64/ztmkworld b/bin/mkworld/build/linux_amd64/ztmkworld similarity index 100% rename from ztnodeid/build/linux_amd64/ztmkworld rename to bin/mkworld/build/linux_amd64/ztmkworld diff --git a/ztnodeid/build/linux_arm64/ztmkworld b/bin/mkworld/build/linux_arm64/ztmkworld similarity index 100% rename from ztnodeid/build/linux_arm64/ztmkworld rename to bin/mkworld/build/linux_arm64/ztmkworld diff --git a/ztnodeid/cmd/mkworld/main.go b/bin/mkworld/cmd/mkworld/main.go similarity index 100% rename from ztnodeid/cmd/mkworld/main.go rename to bin/mkworld/cmd/mkworld/main.go diff --git a/ztnodeid/go.mod b/bin/mkworld/go.mod similarity index 100% rename from ztnodeid/go.mod rename to bin/mkworld/go.mod diff --git a/ztnodeid/go.sum b/bin/mkworld/go.sum similarity index 100% rename from ztnodeid/go.sum rename to bin/mkworld/go.sum diff --git a/ztnodeid/pkg/node/errs.go b/bin/mkworld/pkg/node/errs.go similarity index 100% rename from ztnodeid/pkg/node/errs.go rename to bin/mkworld/pkg/node/errs.go diff --git a/ztnodeid/pkg/node/identity.go b/bin/mkworld/pkg/node/identity.go similarity index 100% rename from ztnodeid/pkg/node/identity.go rename to bin/mkworld/pkg/node/identity.go diff --git a/ztnodeid/pkg/node/node.go b/bin/mkworld/pkg/node/node.go similarity index 100% rename from ztnodeid/pkg/node/node.go rename to bin/mkworld/pkg/node/node.go diff --git a/ztnodeid/pkg/node/world.go b/bin/mkworld/pkg/node/world.go similarity index 100% rename from ztnodeid/pkg/node/world.go rename to bin/mkworld/pkg/node/world.go diff --git a/ztnodeid/pkg/ztcrypto/identity.go b/bin/mkworld/pkg/ztcrypto/identity.go similarity index 100% rename from ztnodeid/pkg/ztcrypto/identity.go rename to bin/mkworld/pkg/ztcrypto/identity.go diff --git a/docs/docs/Installation/FreeBSD.md b/docs/docs/Installation/FreeBSD.md index 15294b3c..fa261d7c 100644 --- a/docs/docs/Installation/FreeBSD.md +++ b/docs/docs/Installation/FreeBSD.md @@ -100,7 +100,7 @@ setenv PRISMA_QUERY_ENGINE_LIBRARY /root/prisma-engines/target/release/libquery_ 8. Copy mkworld binary: ```bash - cp ztnodeid/build/freebsd_amd64/ztmkworld /usr/local/bin/ztmkworld + cp bin/mkworld/build/freebsd_amd64/ztmkworld /usr/local/bin/ztmkworld ``` 9. Run server: ```bash diff --git a/install.ztnet/bash/ztnet.sh b/install.ztnet/bash/ztnet.sh index c5fb0482..29355e3b 100755 --- a/install.ztnet/bash/ztnet.sh +++ b/install.ztnet/bash/ztnet.sh @@ -984,7 +984,7 @@ pull_checkout_ztnet check_postgres_access_and_prompt_password "$POSTGRES_USER" "$POSTGRES_PASSWORD" "$POSTGRES_DB" # Copy mkworld binary -cp "$TEMP_REPO_DIR/ztnodeid/build/linux_$ARCH/ztmkworld" /usr/local/bin/ztmkworld +cp "$TEMP_REPO_DIR/bin/mkworld/build/linux_$ARCH/ztmkworld" /usr/local/bin/ztmkworld NEXT_PUBLIC_APP_VERSION="${CUSTOM_VERSION:-$latestTag}" diff --git a/prisma/migrations/20240820103254_moon/migration.sql b/prisma/migrations/20240820103254_moon/migration.sql new file mode 100644 index 00000000..91e603ee --- /dev/null +++ b/prisma/migrations/20240820103254_moon/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "Planet" ADD COLUMN "isMoon" BOOLEAN NOT NULL DEFAULT false; + +-- AlterTable +ALTER TABLE "RootNodes" ADD COLUMN "isMoon" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 34acaf36..bbe886b2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -60,6 +60,7 @@ model Planet { plID BigInt @default(0) plBirth BigInt @default(0) plRecommend Boolean @default(false) + isMoon Boolean @default(false) rootNodes RootNodes[] globalOptions GlobalOptions? } @@ -68,6 +69,7 @@ model RootNodes { id Int @id @default(autoincrement()) Planet Planet @relation(fields: [PlanetId], references: [id], onDelete: Cascade) PlanetId Int + isMoon Boolean @default(false) comments String? identity String endpoints Json diff --git a/src/components/adminPage/controller/privateRoot.tsx b/src/components/adminPage/controller/privateRoot.tsx index 988b447b..86f96f2e 100644 --- a/src/components/adminPage/controller/privateRoot.tsx +++ b/src/components/adminPage/controller/privateRoot.tsx @@ -97,6 +97,11 @@ const PrivateRoot = () => { toast.error(error.message); }); }; + + // generate the moon id from the first node that has ismoon set to true + const isMoonIdentity = getPlanet?.rootNodes?.filter((node) => node.isMoon); + const moonId = isMoonIdentity?.[0]?.identity.trim().split(":")[0]; + return (
Root #{i + 1}
-- Comments: {node.comments} -
-- Endpoints: {node.endpoints.toString()} -
-- Identity: {node.identity.substring(0, 50)} -
+Root #{i + 1}
+ {node.isMoon ? ( + + {`zerotier-cli orbit ${moonId} ${ + node.identity.split(":")[0] + }`} + + ) : null} ++ Comments: {node.comments} +
++ Endpoints: {node.endpoints.toString()} +
++ Identity: {node.identity.substring(0, 50)} +
++ WorldType: {node.isMoon ? "Moon" : "Planet"} +
++ Moon file is available for download at the following URL: +
+ + api/moon + ++ Planet file is available for download at the following URL: +
+ + {t("controller.generatePlanet.downloadPlanetUrl")} + + + )} +- {t("controller.generatePlanet.downloadPlanetInfo")}{" "} - - {t("controller.generatePlanet.downloadPlanetUrl")} - -
-