diff --git a/docker/all-in-one/Dockerfile b/docker/all-in-one/Dockerfile new file mode 100644 index 0000000..0481453 --- /dev/null +++ b/docker/all-in-one/Dockerfile @@ -0,0 +1,81 @@ +# ---- initialize build stage +FROM node:current-alpine as builder + +# ---- build ZeroTier-One +RUN apk add --update --no-cache alpine-sdk linux-headers \ + && git clone --quiet https://github.com/zerotier/ZeroTierOne.git /src \ + && make -C /src -f make-linux.mk + +# ---- build Zero-UI +ENV INLINE_RUNTIME_CHUNK=false +ENV GENERATE_SOURCEMAP=false + +RUN yarn set version berry + +WORKDIR /app/frontend +COPY ./frontend/package*.json /app/frontend +COPY ./frontend/yarn.lock /app/frontend +RUN yarn install + +COPY ./frontend /app/frontend +RUN yarn build + +# ---- build ZeroNSd \ +FROM rust:alpine as rbuild + +ARG IS_LOCAL=0 +ARG VERSION=main +ARG IS_TAG=0 + +RUN apk add --update --no-cache git libressl-dev musl-dev \ + && git clone https://github.com/zerotier/zeronsd.git \ + && cd zeronsd \ + && sh cargo-docker.sh + +# ---- initialize deploy stage +FROM node:current-alpine + +LABEL description="ZeroTier One as Docker Image" +LABEL org.opencontainers.image.authors="mcondarelli@soft-in.com" + +# ---- copy ZeroTier-One +ARG ZT_VERSION + +LABEL version="${ZT_VERSION}" + +RUN apk add --update --no-cache libc6-compat libstdc++ + +COPY --from=builder /src/zerotier-one /usr/sbin/ +RUN mkdir -p /var/lib/zerotier-one \ + && ln -s /usr/sbin/zerotier-one /usr/sbin/zerotier-idtool \ + && ln -s /usr/sbin/zerotier-one /usr/sbin/zerotier-cli + +EXPOSE 9993/udp + +# ---- copy Zero-UI +WORKDIR /app/frontend/build +COPY --from=builder /app/frontend/build /app/frontend/build/ + +WORKDIR /app/backend +COPY ./backend/package*.json /app/backend +COPY ./backend/yarn.lock /app/backend +RUN yarn install + +COPY ./backend /app/backend + +EXPOSE 4000 +ENV NODE_ENV=production +ENV ZU_SECURE_HEADERS=true +ENV ZU_SERVE_FRONTEND=true + +# ---- copy ZeroNSd +COPY --from=rbuild /usr/local/cargo/bin/zeronsd /usr/sbin/ + +# ---- final setup + +VOLUME /var/lib/zerotier + +COPY docker/all-in-one/entrypoint.sh /entrypoint.sh +RUN chmod 755 /entrypoint.sh + +CMD /entrypoint.sh diff --git a/docker/all-in-one/Dockerfile.debian b/docker/all-in-one/Dockerfile.debian new file mode 100644 index 0000000..31830b8 --- /dev/null +++ b/docker/all-in-one/Dockerfile.debian @@ -0,0 +1,75 @@ +# ---- initialize build stage +FROM node:current-bullseye as builder + +# ---- build ZeroTier-One +RUN apt-get update && apt-get install -y build-essential \ + && git clone --quiet https://github.com/zerotier/ZeroTierOne.git /src \ + && make -C /src -f make-linux.mk + +# ---- build Zero-UI +ENV INLINE_RUNTIME_CHUNK=false +ENV GENERATE_SOURCEMAP=false + +RUN yarn set version berry + +WORKDIR /app/frontend +COPY ./frontend/package*.json /app/frontend +COPY ./frontend/yarn.lock /app/frontend +RUN yarn install + +COPY ./frontend /app/frontend +RUN yarn build + +# ---- build ZeroNSd \ +FROM rust:bullseye as rbuild + +ARG IS_LOCAL=0 +ARG VERSION=main +ARG IS_TAG=0 + +COPY ./docker/all-in-one/zeronsd.patch /tmp/zeronsd.patch +RUN apt-get update && apt-get install --no-install-recommends -y git libssl-dev \ + && git clone https://github.com/zerotier/zeronsd.git \ + && cd zeronsd \ + && patch -p 1 /dev/null | grep -q zerotier-one + return $? +} + +echo "starting zerotier" +setsid /usr/sbin/zerotier-one & + +while ! grepzt +do + echo "zerotier hasn't started, waiting a second" + sleep 1 +done + +echo "joining networks" + +for i in "$@" +do + echo "joining $i" + + while ! zerotier-cli join "$i" + do + echo "joining $i failed; trying again in 1s" + sleep 1 + done +done + +echo "starting node" +node ./bin/www +echo "at end" diff --git a/docker/all-in-one/zeronsd.patch b/docker/all-in-one/zeronsd.patch new file mode 100644 index 0000000..81627c3 --- /dev/null +++ b/docker/all-in-one/zeronsd.patch @@ -0,0 +1,12 @@ +diff --git a/src/utils.rs b/src/utils.rs +index 0f62d52..0f90e69 100644 +--- a/src/utils.rs ++++ b/src/utils.rs +@@ -21,6 +21,7 @@ pub(crate) fn central_config(token: String) -> Configuration { + let mut config = Configuration::default(); + config.user_agent = Some(version()); + config.bearer_access_token = Some(token); ++ config.base_path = "http://localhost:3000/api".to_string(); + return config; + } +