codex-storage / codex-marketplace-ui

Codex marketplace UI allowing buy and sell operations in the Codex decentralized storage network
https://app.codex.storage
Apache License 2.0
0 stars 0 forks source link

Docker image #53

Closed AuHau closed 1 month ago

AuHau commented 1 month ago

I would like to self-host the UI because of HTTP/HTTPS API mismatches. Docker image for that would be great.

veaceslavdoina commented 1 month ago

I can take over this one an implement multi-steps builds based on the previous experience.

We have existing files already:

veaceslavdoina commented 1 month ago

Did a check with a multi-stage build and Nginx as a base image. And we can check how it works.

At least one no so convenient thing we have with that approach is that it will all the time point Codex client node URL to the http://127.0.0.1:8080, as it is passed at build time, and you should update it each time you run it the app.

Check

docker run --rm -p 3000:80 codexstorage/codex-marketplace-ui:latest

http://localhost:3000

Build

docker build \
  --build-arg VITE_CODEX_API_URL=http://127.0.0.1:8080 \
  --build-arg VITE_GEO_IP_URL=http://127.0.0.1 \
  --no-cache \
  -f Dockerfile \
  -t codex-marketplace-ui .

Dockerfile

# Variables
ARG BUILDER=node:22-alpine
ARG IMAGE=nginx:1.27-alpine-slim
ARG APP_USER=root
ARG BUILD_HOME=/app
ARG BUILD_OUT=dist
ARG APP_HOME=/usr/share/nginx/html
ARG VITE_CODEX_API_URL=${VITE_CODEX_API_URL:-http://127.0.0.1:8080}
ARG VITE_GEO_IP_URL=${VITE_GEO_IP_URL:-http://127.0.0.1:8080}

# Build
FROM ${BUILDER} AS builder

ARG APP_USER
ARG BUILD_HOME
ARG VITE_CODEX_API_URL
ARG VITE_GEO_IP_URL

WORKDIR ${BUILD_HOME}
COPY --chown=${APP_USER}:${APP_USER} . .

RUN npm install
RUN npm run build

# Create
FROM ${IMAGE}

ARG APP_USER
ARG BUILD_HOME
ARG BUILD_OUT
ARG APP_HOME

WORKDIR ${APP_HOME}
COPY --chown=${APP_USER}:${APP_USER} --from=builder ${BUILD_HOME}/${BUILD_OUT} .
2-towns commented 1 month ago

@veaceslavdoina I don't think VITE_GEO_IP_URL should be http://127.0.0.1:8080; it should point to a Docker instance of https://hub.docker.com/r/hakanensari/country, right ?

veaceslavdoina commented 1 month ago

I don't think VITE_GEO_IP_URL should be http://127.0.0.1:8080/; it should point to a Docker instance of https://hub.docker.com/r/hakanensari/country, right ?

Yes and in Dockerfile we use ARG VITE_GEO_IP_URL=${VITE_GEO_IP_URL:-http://127.0.0.1:8080} and during the build we override it using value from GitHub Actions secrets.

Just created a PR #55.

AuHau commented 1 month ago

@veaceslavdoina I guess we can close this?

veaceslavdoina commented 1 month ago

If all is working as expected let's close it.

Docker images are located in the codexstorage/codex-marketplace-ui repository. Maybe it make sense to rename it like codexstorage/codex-app, but that is another story.

AuHau commented 1 month ago

So I have just deployed it and actually it does not work as expected 🙈

The problem is with Ngnix configuration - it correctly serves the file at root, but if you navigate to some subpage for example http://codex.cera.uhlici.cz/dashboard/availabilities and reload the page you will get 404. The UI should be served on all paths.