diff --git a/.github/workflows/ui.yaml b/.github/workflows/ui.yaml new file mode 100644 index 000000000..c267a4b4e --- /dev/null +++ b/.github/workflows/ui.yaml @@ -0,0 +1,77 @@ +name: NodeJS with Webpack + +on: + workflow_dispatch: + inputs: + deployTo: + type: choice + description: "Environment to deploy to" + options: + - "dev" + - "prod" + default: "dev" + push: + branches: [ "main" ] + +jobs: + build: + environment: web + runs-on: ubuntu-latest + permissions: + id-token: write + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: GitHub Tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Use Node.js 20.x + uses: actions/setup-node@v3 + with: + node-version: 20.x + + - name: NPM Cache + uses: actions/cache@v3 + with: + path: | + ~/.npm + ~/.cache + ./node_modules + key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-npm- + + - name: Install dependencies + run: npm install + + - name: Build + env: + CI: false + run: npm run build + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_PAT }} + - name: Build and push Docker images + uses: docker/build-push-action@v4 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64 # Add multi-platform support + + tags: + ghcr.io/${{ github.repository_owner }}/web-ui:${{ steps.tag_version.outputs.new_tag }}-${{ github.event.inputs.deployTo == '' && 'dev' || github.event.inputs.deployTo }} + file: docker/WebUiDockerfile + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.gitignore b/.gitignore index 866f4e5d2..5b47c9d05 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ build/* cache/* # Environment files -*.env # PEM files *.pem diff --git a/assets/web-ui/nginx.conf b/assets/web-ui/nginx.conf new file mode 100755 index 000000000..1d997c324 --- /dev/null +++ b/assets/web-ui/nginx.conf @@ -0,0 +1,22 @@ +server { + + listen 7298; + + # This block is to catch workspaces and redirect to workspace/dashboard + # location ~ ^(/(?!invitation|login|sign-up|workspaces))[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$ { + # rewrite ^((/(?!invitation|login|sign-up|workspaces))[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$) $1/dashboard redirect; + # } + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + + location = /50x.html { + root /usr/share/nginx/html; + } + +} diff --git a/docker/WebUiDockerfile b/docker/WebUiDockerfile new file mode 100755 index 000000000..b800b98d7 --- /dev/null +++ b/docker/WebUiDockerfile @@ -0,0 +1,16 @@ +# Prepare nginx +FROM docker.io/nginx:1.25.0-alpine +COPY ./build /usr/share/nginx/html +COPY ./.env.example /usr/share/nginx/html/.env +RUN rm /etc/nginx/conf.d/default.conf +COPY ./assets/web-ui/nginx.conf /etc/nginx/conf.d + +RUN apk add --update npm +RUN npm i -g runtime-env-cra@0.2.4 + +WORKDIR /usr/share/nginx/html + +# Fire up nginx +EXPOSE 7298 +#CMD ["nginx", "-g", "daemon off;"] +CMD ["/bin/sh", "-c", "runtime-env-cra && nginx -g \"daemon off;\""]