From f321154b1bf40b1731bcb24ea7c2dd9fa6b6c385 Mon Sep 17 00:00:00 2001 From: PastaGringo Date: Thu, 30 May 2024 13:03:56 +0000 Subject: [PATCH] code reworked to simplify --- Dockerfile | 20 ++++++++++------ docker-compose.yml | 14 ++++++----- entrypoint.sh | 58 +++++++++++++++------------------------------- 3 files changed, 40 insertions(+), 52 deletions(-) diff --git a/Dockerfile b/Dockerfile index d074fa5..02b4050 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,16 @@ FROM node:alpine as build -RUN apk add --no-cache git nginx -RUN git clone https://github.com/dtonon/oracolo.git /app -WORKDIR /app -COPY entrypoint.sh /app/ -COPY nginx.conf /app/ -RUN chmod +x /app/entrypoint.sh -ENTRYPOINT [ "/app/entrypoint.sh" ] +RUN apk add --no-cache git +RUN git clone https://github.com/dtonon/oracolo.git /build +WORKDIR /build +RUN npm install +RUN npm run build + +FROM nginx:stable-alpine +COPY --from=build /build/dist/ /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY entrypoint.sh / +RUN chmod +x /entrypoint.sh +ENTRYPOINT [ "/entrypoint.sh" ] + EXPOSE 8080/tcp CMD ["/usr/sbin/nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8ade853..d7005dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3.8' -services: - +services: + traefik: image: "traefik:latest" container_name: "traefik" @@ -39,13 +39,14 @@ services: oracolo: container_name: oracolo - image: pastagringo/oracolo-docker - #build: - # context: . + # image: pastagringo/oracolo-docker + build: + context: . environment: - NPUB=${NPUB} - RELAYS=${RELAYS} - TOP_NOTES_NB=${TOP_NOTES_NB} + - SHORT_CHARS_NB=${SHORT_CHARS_NB} # ports: # - 8080:8080 labels: @@ -55,4 +56,5 @@ services: - "traefik.http.routers.oracolo.entrypoints=websecure" - "traefik.http.routers.oracolo.tls.certresolver=selfhostedservices" - "traefik.http.middlewares.accesscontrol.headers.customResponseHeaders.access-control-allow-origin=*" - - "traefik.http.routers.oracolo.middlewares=accesscontrol@docker" \ No newline at end of file + - "traefik.http.routers.oracolo.middlewares=accesscontrol@docker" + diff --git a/entrypoint.sh b/entrypoint.sh index 10eab9b..812037c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,65 +7,45 @@ echo "| O || / | |/ / | O || |___ | O |"; echo "| || \ | _ / \_ | || || |"; echo "| || . \| | \ || || || |"; echo " \___/ |__|\_||__|__|\____| \___/ |_____| \___/ "; -echo +echo " "; echo "Oracolo dtonon's repo: https://github.com/dtonon/oracolo" -src_index_html="/app/index.html" +echo "Docker image repo: https://github.com/PastaGringo/oracolo-docker" echo -echo "╭────────────────────────────╮" -echo "│ Docker Compose Env Vars ⤵️ │" -echo "╰────────────────────────────╯" +echo "╭───────────────────────╮" +echo "│ Docker Env Vars... ⤵️ │" +echo "╰───────────────────────╯" echo -printf "%-15s : %s\n" "NPUB" "$NPUB" -printf "%-15s : %s\n" "RELAYS" "$RELAYS" -printf "%-15s : %s\n" "TOP_NOTES_NB" "$TOP_NOTES_NB" +echo "> NPUB : $NPUB" +echo "> RELAYS : $RELAYS" +echo "> TOP_NOTES : $TOP_NOTES_NB" +echo "> SHORT_CHARS : $SHORT_CHARS_NB" echo echo "╭───────────────────────────╮" -echo "│ Configuring Oracolo... ⤵️ │" +echo "│ Configuring Oracolo... ⏳ │" echo "╰───────────────────────────╯" +src_index_html="/usr/share/nginx/html/index.html" echo -echo -n "> Updating npub key with $NPUB... " +echo -n "> Updating author npub key... " sed -i "s/replace_with_your_npub/$NPUB/" $src_index_html echo "✅" -echo -n "> Updating nostr relays with $RELAYS... " +echo -n "> Updating nostr relays... " old_relays="wss://nos.lol, wss://relay.damus.io, wss://nostr.wine" RELAYS=$(echo $RELAYS | sed 's/^"//' | sed 's/"$//') sed -i "s|$old_relays|$RELAYS|g" $src_index_html echo "✅" -echo -n "> Updating TOP_NOTE with value $TOP_NOTES_NB... " +echo -n "> Updating top-notes... " old_TOP_NOTES='name="top-notes" value="0"' TOP_NOTES="name=\"top-notes\" value=\"$TOP_NOTES_NB\"" sed -i "s|$old_TOP_NOTES|$TOP_NOTES|g" $src_index_html echo "✅" -echo -echo "╭───────────────────────╮" -echo "│ Installing Oracolo ⤵️ │" -echo "╰───────────────────────╯" -npm install -echo -echo ">>> done ✅" -echo -echo "╭─────────────────────╮" -echo "│ Building Oracolo ⤵️ │" -echo "╰─────────────────────╯" -npm run build -echo -echo ">>> done ✅" -echo -echo -n "> Copying Oracolo built index.html to nginx usr/share/nginx/html... " -mkdir /usr/share/nginx/html -cp /app/dist/index.html /usr/share/nginx/html -echo "✅" -echo -echo "╭────────────────────────╮" -echo "│ Configuring Nginx... ⤵️ │" -echo "╰────────────────────────╯" -echo -echo -n "> Copying default nginx.conf file... " -cp /app/nginx.conf /etc/nginx/http.d/oracolo.conf +echo -n "> Updating short-chars... " +old_SHORT_CHARS='name="short-chars" value="0"' +SHORT_CHARS="name=\"short-chars\" value=\"$SHORT_CHARS_NB\"" +sed -i "s|$old_SHORT_CHARS|$SHORT_CHARS|g" $src_index_html echo "✅" echo echo "╭──────────────────────╮" echo "│ Starting Nginx... 🚀 │" echo "╰──────────────────────╯" echo -exec "$@" +exec "$@" \ No newline at end of file