it-tools icon indicating copy to clipboard operation
it-tools copied to clipboard

[TOOL IMPROVEMENT] Dockerfile with subfolder url

Open DeAlexPesh opened this issue 2 years ago • 11 comments

FROM node:lts-alpine AS build
ARG TOOLZ_REPO="https://github.com/CorentinTh/it-tools.git"
RUN apk add --no-cache git \
 && rm -rf /var/cache/apk/*
WORKDIR /app
RUN git clone ${TOOLZ_REPO} toolz
WORKDIR /app/toolz
# make sub url
ARG SUB_URL=
RUN if [[ -n "$SUB_URL" ]] \
 ; then \
 sed -i -e "s|href=\"/|href=\"|" index.html \
 && sed -i -e "s|src: \'/|src: \'|" vite.config.ts \
 && sed -i -e "s|routes:|base: config.app.baseUrl, routes:|" src/router.ts \
 && sed -i -e "s|resolve:|base: process.env.SUB_URL + '/', resolve:|" vite.config.ts \
 && sed -i -e "s|default: '/',|default: process.env.SUB_URL,|" src/config.ts \
 && sed -i -e "s|start_url: '/?utm_source=pwa&utm_medium=pwa',|start_url: process.env.SUB_URL + '/?utm_source=pwa\&utm_medium=pwa',|" vite.config.ts \
 ; fi
# compile
RUN npm install -g pnpm \
 && pnpm i --frozen-lockfile \
 && pnpm build

FROM nginx:stable-alpine AS production
COPY --from=build /app/toolz/dist /usr/share/nginx/html
COPY --from=build /app/toolz/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

change arg SUB_URL to need subfolder ex: ARG SUB_URL=/sub for http://domain.org/sub/ build image:

docker build -t it-tools:mode /folder_with_dockerfile/. -f /folder_with_dockerfile/Dockerfile

DeAlexPesh avatar May 30 '23 18:05 DeAlexPesh

@CorentinTh Do you plan to add this excellent option in the it-tools code?

cvc90 avatar Jun 04 '23 13:06 cvc90

Hi @DeAlexPesh and @cvc90 , implemented in my fork, if you arr interested in up to date version of it-tools, I made kind of a fork here : https://github.com/sharevb/it-tools (https://sharevb-it-tools.vercel.app/ and docker images https://github.com/sharevb/it-tools/pkgs/container/it-tools)

sharevb avatar Feb 23 '25 12:02 sharevb

Hi @DeAlexPesh and @cvc90 , implemented in my fork, if you arr interested in up to date version of it-tools, I made kind of a fork here : sharevb/it-tools (sharevb-it-tools.vercel.app and docker images sharevb/it-tools/pkgs/container/it-tools)

Thanks, I'll check it out! 😄

UPDATE: The new features are interesting, but it still doesn't have the direct possibility of indicating the base path in a subfolder when creating Docker, it is not possible to use it through Dockerfile if you want to use Watchdog for Docker, if so, could you tell me how to use it?

cvc90 avatar Mar 13 '25 14:03 cvc90

Hi @cvc90, it should work with the procedure here : https://github.com/sharevb/it-tools?tab=readme-ov-file#build-docker-image-for-a-subfolder ; subfolder must be set at docker build time (not at runtime)

sharevb avatar Mar 15 '25 13:03 sharevb

Hi @cvc90, it should work with the procedure here : sharevb/it-tools#build-docker-image-for-a-subfolder ; subfolder must be set at docker build time (not at runtime)

Hi @sharevb,

As I mentioned, this method doesn't work for me with Watchdog, for it to work, it must be done without a Dockerfile.

The section you're referring to has a URL to a comment that doesn't work.

Thanks

cvc90 avatar Mar 19 '25 16:03 cvc90

Hi @cvc90 , I will try to release a docker image with "/it-tools/" as BASE_URL

sharevb avatar Apr 05 '25 09:04 sharevb

Hi @DeAlexPesh , @cvc90 , implemented BASE_URL (and config sample) in my fork, and published a baseurl-it-tools tag

Detailed explaination: https://github.com/sharevb/it-tools?tab=readme-ov-file#docker-compose-for-hosting-in-a-it-tools-subfolder and https://github.com/sharevb/it-tools?tab=readme-ov-file#docker-compose-for-hosting-in-a-it-tools-subfolder

sharevb avatar Apr 06 '25 20:04 sharevb

Hi @sharevb.

I'm trying what you mentioned, but it doesn't seem to work

The nginx example is not correct

Current Nginx example (nginx.conf)

server {
    listen 8080;
    server_name _;

    location /it-tools/ {
        proxy_pass http://it-tools-subfolder:8080/;
    }
}

Fixed Nginx example

server {
    listen 8080;
    server_name _;

    location /it-tools/ {
        proxy_pass http://it-tools-subfolder:8080/it-tools/;
    }
}

When trying to access http://it-tools-subfolder-server:8080/it-tools/, it doesn't load, I get a blank screen.

When trying to access http://it-tools-subfolder-server/it-tools/, it doesn't load, I get a blank screen.

I'm getting 400 errors in the log

Image

The normal version works correctly but it is not possible to perform the reverse proxy function

Any idea why this error occurs?

cvc90 avatar Apr 07 '25 15:04 cvc90

Hi @cvc90 , may be I need to clarify in README : it-tools-subfolder is internal server. With my sample in https://github.com/sharevb/it-tools/tree/chore/all-my-stuffs/docker-subfolder-sample, you need to access http://localhost:8080/it-tools/ (that is the reverse proxy). This is the only address that works.

sharevb avatar Apr 08 '25 11:04 sharevb

Hi @sharevb,

I can't get it to work.

Could you check that the Docker version is working correctly?

I can access the normal version perfectly.

When I access the Docker version directly through the Docker port http://localhost:8080/it-tools/, the screen loads but goes blank and displays these loading errors.

Image

When I access the Docker version directly through the reverse proxy http://localhost/it-tools/, the screen loads but goes blank and displays these loading errors.

Image

I think that the error comes from the “special” docker that does not do correctly the url redirection or some problem with the mime type of the Nginx server.

I have many other services running this way without any issues.

cvc90 avatar Apr 08 '25 22:04 cvc90

Hi @cvc90 , I tested with Docker Desktop and WSL2, using docker compose up from https://github.com/sharevb/it-tools/tree/chore/all-my-stuffs/docker-subfolder-sample using procedure here : https://github.com/sharevb/it-tools/tree/chore/all-my-stuffs?tab=readme-ov-file#docker-compose-for-hosting-in-a-it-tools-subfolder

And http://localhost:8080/it-tools/ respond correctly

I cannot reproduce these strange errors text/html.

sharevb avatar Apr 13 '25 19:04 sharevb