From e988a0ecfe9c23bab5455c0ba3186de8420f2cf1 Mon Sep 17 00:00:00 2001 From: Slava <20563034+veaceslavdoina@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:22:12 +0300 Subject: [PATCH] Set Nginx port from variable (#59) * Set Nginx port from a variable * Add latest tag only from tags and default branch --- .github/workflows/docker.yml | 2 ++ docker/Dockerfile | 5 ++++- docker/README.md | 11 +++++++++++ docker/default.conf.template | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0bed160..2159acb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -23,4 +23,6 @@ jobs: build-and-push: name: Build and Push uses: ./.github/workflows/docker-reusable.yml + with: + tag_latest: ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/') }} secrets: inherit diff --git a/docker/Dockerfile b/docker/Dockerfile index 6686681..df68c31 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,6 +5,7 @@ ARG APP_USER=root ARG BUILD_HOME=/app ARG BUILD_OUT=dist ARG APP_HOME=${BUILD_HOME} +ARG APP_PORT=${APP_PORT:-80} ARG NGINX_TEMPLATE=docker/default.conf.template 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} @@ -32,6 +33,7 @@ ARG APP_USER ARG BUILD_HOME ARG BUILD_OUT ARG APP_HOME +ARG APP_PORT ARG NGINX_TEMPLATE WORKDIR ${APP_HOME} @@ -40,5 +42,6 @@ COPY ${NGINX_TEMPLATE} /etc/nginx/templates COPY --chown=${APP_USER}:${APP_USER} --from=builder ${BUILD_HOME}/${BUILD_OUT} . ENV APP_HOME=${APP_HOME} +ENV APP_PORT=${APP_PORT} -EXPOSE 80 +EXPOSE ${APP_PORT} diff --git a/docker/README.md b/docker/README.md index 229abfb..810617c 100644 --- a/docker/README.md +++ b/docker/README.md @@ -46,3 +46,14 @@ ``` Access UI on http://localhost:3000. + + And we also can set Nginx custom port using `APP_PORT` variable. That is useful when use the `host` network mode for a container + ```shell + docker run \ + --rm \ + --name codex-marketplace-ui \ + --net=host \ + -e 'APP_PORT=3000' \ + -p 3000:3000 \ + codexstorage/codex-marketplace-ui:latest + ``` diff --git a/docker/default.conf.template b/docker/default.conf.template index cb820e5..e4c09cd 100644 --- a/docker/default.conf.template +++ b/docker/default.conf.template @@ -1,5 +1,5 @@ server { - listen 80; + listen ${APP_PORT}; server_name localhost; root /usr/share/nginx/html;