Skip to content

Commit

Permalink
Build on metal, serve using static-web-server
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Sep 22, 2024
1 parent 9ac4b35 commit 9c928d5
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 271 deletions.
16 changes: 8 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# dev container stuff that might end up here bc of the dev environment
.git
.github
.gitignore
.dockerignore
Dockerfile
README.md
src

node_modules
.config/
.npm/
.cache/
.yarnrc
npm-debug.log*
yarn-debug.log*
yarn-error.log*
test-results
playwright-report
.nyc_output
Expand Down
16 changes: 13 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# ChRIS_ui development and build-time configuration file.
#
# DO NOT edit this file `.env` to re-configure ChRIS_ui. Instead, create a copy
#
# cp .env .env.development.local
#
# And edit the copy `.env.development.local` instead.
#
# This file should be edited to declare or remove variables.
# Whenever you edit this file, be sure to update .env.production
# and docker-entrypoint.sh as well.


BROWSER="chrome"

Expand All @@ -13,9 +25,7 @@ VITE_PFDCM_URL="http://localhost:4005/"
# (optional) set URL of an OHIF browser which has the same studies as the PFDCM
# VITE_OHIF_URL="http://localhost:8042/ohif/"

VITE_PFDCM_CUBEKEY="local"
VITE_PFDCM_SWIFTKEY="local"
VITE_SOURCEMAP='false'

# Set URL for the store if you want to see it in the sidebar
VITE_CHRIS_STORE_URL= "http://rc-live.tch.harvard.edu:32222/api/v1/"
VITE_CHRIS_STORE_URL= "https://cube.chrisproject.org/api/v1/"
16 changes: 16 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file contains placeholder values which will be overwritten by ./docker-entrypoint.sh.

VITE_CHRIS_UI_URL="b87f4fda-012a-4564-8c36-096e496cbedf"
VITE_CHRIS_UI_USERS_URL="b87f4fda-012a-4564-8c36-096e496cbedfusers/"
VITE_CHRIS_UI_AUTH_URL="b87f4fda-012a-4564-8c36-096e496cbedfauth-token/"

VITE_CHRIS_STORE_URL="79e63221-ccf9-43c3-bf0d-45d05db72c48"

VITE_PFDCM_URL="700e747e-619f-4007-ad8d-47677c0d0b46"

VITE_OHIF_URL="ea1cf042-73f0-43a1-93da-86ff93e5ac19"

VITE_ALPHA_FEATURES='production'

VITE_SOURCEMAP='false'

64 changes: 36 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
name: build
name: Build

on:
push:
branches: [ master, staging ]
pull_request:
branches: [ master, staging ]

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
if: github.repository_owner == 'FNNDSC'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0" # necessary for `npm run print-version`
- name: Get info
id: info
run: |
version="$(npm run -s print-version | tr '+' '-')"
echo "Version: $version"
echo "version_string=$version" >> "$GITHUB_OUTPUT"

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm build

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/fnndsc/chris_ui
ghcr.io/fnndsc/chris_ui
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short,prefix=
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
with:
Expand All @@ -36,34 +60,18 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get postfix of latest
id: postfix_of_latest
run: |
if [[ $GITHUB_REF_TYPE == tag || $GITHUB_REF_NAME == master ]]; then
echo "Postfix of latest: ''"
echo "postfix_of_latest=" >> $GITHUB_OUTPUT
else
echo "Postfix of latest: -$GITHUB_REF_NAME"
echo "postfix_of_latest=-$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
fi
- name: Build and push
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
tags: |
docker.io/fnndsc/chris_ui:latest${{ steps.postfix_of_latest.outputs.postfix_of_latest}}
docker.io/fnndsc/chris_ui:${{ steps.info.outputs.version_string }}${{ steps.postfix_of_latest.outputs.postfix_of_latest}}
ghcr.io/fnndsc/chris_ui:latest${{ steps.postfix_of_latest.outputs.postfix_of_latest}}
ghcr.io/fnndsc/chris_ui:${{ steps.info.outputs.version_string }}${{ steps.postfix_of_latest.outputs.postfix_of_latest}}
tags: ${{ steps.meta.outputs.tags }}
context: .
file: ./Dockerfile
platforms: linux/amd64
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7,linux/386
push: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Update DockerHub description
uses: peter-evans/dockerhub-description@v4
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.DS_Store

# Individual settings
.env.*local
.env.*.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand All @@ -36,5 +36,4 @@ yarn-error.log*
.cache/
.yarnrc
dist/
pnpm-lock.yaml
.pnpm-store/
.pnpm-store/
53 changes: 14 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,26 @@
# ChRIS_ui production mode server
# Production image for ChRIS_ui.
#
# Build with
# This is a simple image containing a static web server and the build assets.
#
# docker build -t <name> .
# The web application needs to be built on-the-metal before building this container image.
# Instructions:
#
# For example if building a local version, you could do:
# pnpm build && docker build -t localhost/fnndsc/chris_ui:latest .
#
# docker build -t local/chris_ui .
#
# In the case of a proxy (located at say 10.41.13.4:3128), do:
#
# export PROXY="http://10.41.13.4:3128"
# docker build --build-arg http_proxy=${PROXY} -t local/chris_ui .
#
# To run the server up, do:
#
# docker run --name chris_ui -p 3000:3000 -d local/chris_ui
#
# To run an interactive shell inside this container, do:
#
# docker exec -it chris_ui sh
#
# Tips:
# - for access logging, remove "--quiet" from CMD
# - docker-entrypoint.sh must start as root

FROM ghcr.io/static-web-server/static-web-server:2.33.0-alpine

FROM node:20.17 as builder
COPY ./dist /build
COPY ./.env.production /build/.env.production

WORKDIR /app
COPY . .


RUN npm ci
RUN npm run build


FROM node:20.17-alpine
COPY ./docker-entrypoint.sh /docker-entrypoint.sh

RUN npm i -g sirv-cli

WORKDIR /app
COPY ./static-web-server.toml /etc/static-web-server/config.toml
ENV SERVER_CONFIG_FILE=/etc/static-web-server/config.toml

COPY --from=builder /app/dist /app
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod 444 /build/.env.production && chmod g+rwx /srv \
&& chmod 550 /etc/static-web-server && chmod 440 /etc/static-web-server/*

ENTRYPOINT ["/docker-entrypoint.sh"]
ENV HOST=0.0.0.0 PORT=3000
CMD ["sirv", "--etag", "--single"]
EXPOSE 3000
CMD ["static-web-server"]
44 changes: 0 additions & 44 deletions Dockerfile_dev

This file was deleted.

11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,18 @@ Or, start a local backend and run the "local" server:
npm run dev:local
```

## Build for production
## Container Image

[Source-to-image](https://github.com/openshift/source-to-image#readme)
must be used to build this project for deployment.
_ChRIS\_ui_ can run on Docker, Podman, Kubernetes, etc.

Simple usage:

```shell
s2i build https://github.com/FNNDSC/ChRIS_ui quay.io/fedora/nodejs-20 s2ichrisui
docker run --rm -it -e CHRIS_UI_URL="http://$(hostname):8000/api/v1/" -e PFDCM_URL="http://$(hostname):4005/" -p 8080:80 ghcr.io/fnndsc/chris_ui:staging
```

For more information, see https://chrisproject.org/docs/run/chris_ui

## Analytics

[Ackee](https://ackee.electerious.com/) can be used for website analytics.
Expand Down
Loading

0 comments on commit 9c928d5

Please sign in to comment.