diff --git a/.github/workflows/itkdev_docker_build_develop.yml b/.github/workflows/itkdev_docker_build_develop.yml new file mode 100644 index 00000000..1f97657b --- /dev/null +++ b/.github/workflows/itkdev_docker_build_develop.yml @@ -0,0 +1,54 @@ +--- +on: + push: + branches: + - 'develop' + +# This Action builds to itkdev/* using ./infrastructure/itkdev/* +name: ITK Dev - Build docker image (develop) + +jobs: + docker: + runs-on: ubuntu-latest + env: + VERSION: alpha + APP_VERSION: develop + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: itkdev/os2display-display-client + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set release timestamp + run: | + echo "APP_RELEASE_TIMESTAMP=$(echo $(date +%s))" >> $GITHUB_ENV + echo "APP_RELEASE_TIME=$(echo $(date))" >> $GITHUB_ENV + + - name: Build and push (API) + uses: docker/build-push-action@v4 + with: + context: ./infrastructure/itkdev/ + file: ./infrastructure/itkdev/Dockerfile + build-args: | + APP_VERSION=${{ env.APP_VERSION }} + APP_RELEASE_VERSION=${{ env.APP_VERSION }} + APP_RELEASE_TIMESTAMP=${{ env.APP_RELEASE_TIMESTAMP }} + APP_RELEASE_TIME=${{ env.APP_RELEASE_TIME }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.github/workflows/itkdev_docker_build_tag.yml b/.github/workflows/itkdev_docker_build_tag.yml new file mode 100644 index 00000000..0b2c4ef5 --- /dev/null +++ b/.github/workflows/itkdev_docker_build_tag.yml @@ -0,0 +1,50 @@ +--- +on: + push: + tags: + - '*' + +# This Action builds to itkdev/* using ./infrastructure/itkdev/* +name: ITK Dev - Build docker image (tag) + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: itkdev/os2display-display-client + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set release timestamp + run: | + echo "APP_RELEASE_TIMESTAMP=$(echo $(date +%s))" >> $GITHUB_ENV + echo "APP_RELEASE_TIME=$(echo $(date))" >> $GITHUB_ENV + + - name: Build and push (API) + uses: docker/build-push-action@v4 + with: + context: ./infrastructure/itkdev/ + file: ./infrastructure/itkdev/Dockerfile + build-args: | + APP_VERSION=${{ github.ref }} + APP_RELEASE_VERSION=$GITHUB_REF_NAME + APP_RELEASE_TIMESTAMP=${{ env.APP_RELEASE_TIMESTAMP }} + APP_RELEASE_TIME=${{ env.APP_RELEASE_TIME }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.github/workflows/docker_build_develop.yml b/.github/workflows/os2display_docker_build_develop.yml similarity index 85% rename from .github/workflows/docker_build_develop.yml rename to .github/workflows/os2display_docker_build_develop.yml index 9344f620..42514590 100644 --- a/.github/workflows/docker_build_develop.yml +++ b/.github/workflows/os2display_docker_build_develop.yml @@ -3,7 +3,9 @@ on: push: branches: - 'develop' -name: Build docker image (develop) + +# This Action builds to os2display/* using ./infrastructure/os2display/* +name: OS2display - Build docker image (develop) jobs: docker: @@ -39,8 +41,8 @@ jobs: - name: Build and push (API) uses: docker/build-push-action@v4 with: - context: ./infrastructure/ - file: ./infrastructure/Dockerfile + context: ./infrastructure/os2display/ + file: ./infrastructure/os2display/Dockerfile build-args: | APP_VERSION=${{ env.APP_VERSION }} APP_RELEASE_VERSION=${{ env.APP_VERSION }} diff --git a/.github/workflows/docker_build_tag.yml b/.github/workflows/os2display_docker_build_tag.yml similarity index 84% rename from .github/workflows/docker_build_tag.yml rename to .github/workflows/os2display_docker_build_tag.yml index 0acaf858..4cb54bc2 100644 --- a/.github/workflows/docker_build_tag.yml +++ b/.github/workflows/os2display_docker_build_tag.yml @@ -3,7 +3,9 @@ on: push: tags: - '*' -name: Build docker image (tag) + +# This Action builds to os2display/* using ./infrastructure/os2display/* +name: OS2display - Build docker image (tag) jobs: docker: @@ -35,8 +37,8 @@ jobs: - name: Build and push (API) uses: docker/build-push-action@v4 with: - context: ./infrastructure/ - file: ./infrastructure/Dockerfile + context: ./infrastructure/os2display/ + file: ./infrastructure/os2display/Dockerfile build-args: | APP_VERSION=${{ github.ref }} APP_RELEASE_VERSION=$GITHUB_REF_NAME diff --git a/CHANGELOG.md b/CHANGELOG.md index ccf9b10b..a0480ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. Only slides with a loaded template should be rendered. - [#109](https://github.com/os2display/display-client/pull/109) Change docker image name from `os2display/os2display-client` to `os2display/display-client` to match image name and repository name +- Setup separate image builds for itkdev and os2display ## [1.2.6] - 2023-06-12 diff --git a/infrastructure/etc/confd/templates/config.tmpl b/infrastructure/etc/confd/templates/config.tmpl deleted file mode 100644 index df696098..00000000 --- a/infrastructure/etc/confd/templates/config.tmpl +++ /dev/null @@ -1,19 +0,0 @@ -{ - "apiEndpoint": "{{ getenv "APP_API_ENDPOINT" "/" }}", - "authenticationEndpoint": "{{ getenv "APP_API_AUTHENTICATION_ENDPOINT" "/v1/authentication/token" }}", - "authenticationRefreshTokenEndpoint": "{{ getenv "APP_API_AUTHENTICATION_REFRESH_ENDPOINT" "/v1/authentication/token/refresh" }}", - "dataStrategy": { - "type": "pull", - "config": { - "interval": {{ getenv "APP_DATA_PULL_INTERVAL" "30000" }}, - "endpoint": "{{ getenv "APP_API_PATH" "/" }}" - } - }, - "colorScheme": { - "type": "library", - "lat": {{ getenv "APP_CLIENT_LATITUDE" "56.0" }}, - "lng": {{ getenv "APP_CLIENT_LONGITUDE" "10.0" }} - }, - "schedulingInterval": {{ getenv "APP_SCHEDULING_INTERVAL" "60000" }}, - "debug": {{ getenv "APP_DEBUG" "false" }} -} diff --git a/infrastructure/etc/confd/templates/default.conf.tmpl b/infrastructure/etc/confd/templates/default.conf.tmpl deleted file mode 100644 index 59defbd6..00000000 --- a/infrastructure/etc/confd/templates/default.conf.tmpl +++ /dev/null @@ -1,34 +0,0 @@ -server { - listen 8080; - server_name localhost; - root /var/www/html; - - location {{ getenv "APP_SCREEN_CLIENT_PATH" "/" }} { - rewrite ^{{ getenv "APP_SCREEN_CLIENT_PATH" "/" }}(.*) /$1 break; - index index.html; - autoindex off; - try_files $uri $uri/ =404; - } - - location = {{ getenv "APP_SCREEN_CLIENT_PATH" "" }}/robots.txt { - add_header Content-Type text/plain; - add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive"; - return 200 "User-agent: *\nDisallow: /\n"; - } - - error_log /var/log/nginx/error.log; - access_log /var/log/nginx/access.log; -} - -server { - listen 8081; - server_name localhost; - root /var/www/html/public; - - error_log off; - access_log off; - - location /stub_status { - stub_status; - } -} diff --git a/infrastructure/etc/confd/templates/nginx.conf.tmpl b/infrastructure/etc/confd/templates/nginx.conf.tmpl deleted file mode 100644 index a3961034..00000000 --- a/infrastructure/etc/confd/templates/nginx.conf.tmpl +++ /dev/null @@ -1,45 +0,0 @@ -worker_processes auto; - -error_log /var/log/nginx/error.log warn; -pid /tmp/nginx.pid; - -events { - worker_connections 2048; - multi_accept on; -} - -http { - open_file_cache max=10000 inactive=5m; - open_file_cache_valid 5m; - open_file_cache_min_uses 5; - open_file_cache_errors off; - - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 15 15; - types_hash_max_size 2048; - - server_tokens off; - - gzip on; - gzip_disable "msie6"; - gzip_vary on; - gzip_proxied any; - gzip_comp_level 6; - gzip_buffers 16 8k; - gzip_http_version 1.0; - gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - error_log /dev/stderr; - access_log /dev/stdout main; - - include /etc/nginx/conf.d/*.conf; -} diff --git a/infrastructure/Dockerfile b/infrastructure/itkdev/Dockerfile similarity index 98% rename from infrastructure/Dockerfile rename to infrastructure/itkdev/Dockerfile index 327901e1..20ee1af9 100644 --- a/infrastructure/Dockerfile +++ b/infrastructure/itkdev/Dockerfile @@ -38,7 +38,7 @@ USER root COPY --from=APP_BUILDER /app/build ${APP_PATH} # Copy configuration. -COPY etc/ /etc/ +COPY etc /etc/ # Create release file RUN echo "{\"releaseTimestamp\": $APP_RELEASE_TIMESTAMP, \"releaseTime\": \"$APP_RELEASE_TIME\", \"releaseVersion\": \"$APP_RELEASE_VERSION\"}" > ${APP_PATH}/release.json diff --git a/infrastructure/itkdev/Readme.md b/infrastructure/itkdev/Readme.md new file mode 100644 index 00000000..cb20c4f1 --- /dev/null +++ b/infrastructure/itkdev/Readme.md @@ -0,0 +1,3 @@ +# ITK-development image build + +This folder contains the infrastructure files for building the `itkdev/os2display-display-client` image. diff --git a/infrastructure/docker-entrypoint.sh b/infrastructure/itkdev/docker-entrypoint.sh similarity index 100% rename from infrastructure/docker-entrypoint.sh rename to infrastructure/itkdev/docker-entrypoint.sh diff --git a/infrastructure/etc/confd/conf.d/config.toml b/infrastructure/itkdev/etc/confd/conf.d/config.toml similarity index 100% rename from infrastructure/etc/confd/conf.d/config.toml rename to infrastructure/itkdev/etc/confd/conf.d/config.toml diff --git a/infrastructure/etc/confd/conf.d/default.conf.toml b/infrastructure/itkdev/etc/confd/conf.d/default.conf.toml similarity index 100% rename from infrastructure/etc/confd/conf.d/default.conf.toml rename to infrastructure/itkdev/etc/confd/conf.d/default.conf.toml diff --git a/infrastructure/etc/confd/conf.d/nginx.conf.toml b/infrastructure/itkdev/etc/confd/conf.d/nginx.conf.toml similarity index 100% rename from infrastructure/etc/confd/conf.d/nginx.conf.toml rename to infrastructure/itkdev/etc/confd/conf.d/nginx.conf.toml diff --git a/infrastructure/itkdev/run.sh b/infrastructure/itkdev/run.sh new file mode 100755 index 00000000..0ed816fd --- /dev/null +++ b/infrastructure/itkdev/run.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -eux + +APP_RELEASE_TIMESTAMP=$(date +%s) +APP_RELEASE_TIME=$(date) +APP_VERSION=develop +VERSION=alpha + +docker build --pull --no-cache --build-arg APP_VERSION=${APP_VERSION} --build-arg APP_RELEASE_TIMESTAMP="${APP_RELEASE_TIMESTAMP}" --build-arg APP_RELEASE_TIME="${APP_RELEASE_TIME}" --tag=itkdev/os2display-client:${VERSION} --file="Dockerfile" . + +# docker push itkdev/os2display-client:${VERSION} diff --git a/infrastructure/os2display/Dockerfile b/infrastructure/os2display/Dockerfile new file mode 100644 index 00000000..20ee1af9 --- /dev/null +++ b/infrastructure/os2display/Dockerfile @@ -0,0 +1,62 @@ +FROM node:16 AS APP_BUILDER +LABEL maintainer="ITK Dev " + +ARG APP_VERSION="develop" +ARG APP_RELEASE_VERSION="develop" +ARG APP_RELEASE_TIMESTAMP=0 +ENV APP_PATH=/app + +ADD https://github.com/os2display/display-client/archive/${APP_VERSION}.tar.gz /tmp/app.tar +RUN mkdir -p ${APP_PATH} \ + && tar -zxf /tmp/app.tar --strip-components=1 -C ${APP_PATH} \ + && rm /tmp/app.tar + +WORKDIR ${APP_PATH} + +# Build it. +RUN yarn install \ + && yarn build + +# Remove fixtures +RUN rm -rf public/fixtures + +#### +## Build main application image. +#### +FROM nginxinc/nginx-unprivileged:alpine +LABEL maintainer="ITK Dev " + +ARG APP_VERSION="develop" +ARG APP_RELEASE_VERSION="develop" +ARG APP_RELEASE_TIMESTAMP=0 +ARG APP_RELEASE_TIME=0 +ENV APP_PATH=/var/www/html + +USER root + +# Install the application. +COPY --from=APP_BUILDER /app/build ${APP_PATH} + +# Copy configuration. +COPY etc /etc/ + +# Create release file +RUN echo "{\"releaseTimestamp\": $APP_RELEASE_TIMESTAMP, \"releaseTime\": \"$APP_RELEASE_TIME\", \"releaseVersion\": \"$APP_RELEASE_VERSION\"}" > ${APP_PATH}/release.json + +# Install configuration template handler +ADD https://github.com/kelseyhightower/confd/releases/download/v0.16.0/confd-0.16.0-linux-amd64 /usr/local/bin/confd +RUN chmod +x /usr/local/bin/confd + + +COPY docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh \ + && chown -R $UID:0 ${APP_PATH} \ + && chmod -R g+w ${APP_PATH} + +USER $UID + +WORKDIR ${APP_PATH} + +EXPOSE 8080 + +CMD [ "/docker-entrypoint.sh", "nginx", "-g daemon off;" ] diff --git a/infrastructure/os2display/Readme.md b/infrastructure/os2display/Readme.md new file mode 100644 index 00000000..eff0fb47 --- /dev/null +++ b/infrastructure/os2display/Readme.md @@ -0,0 +1,3 @@ +# OS2display image build + +This folder contains the infrastructure files for building the `os2display/display-client` image. diff --git a/infrastructure/os2display/docker-entrypoint.sh b/infrastructure/os2display/docker-entrypoint.sh new file mode 100644 index 00000000..978fa9f4 --- /dev/null +++ b/infrastructure/os2display/docker-entrypoint.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +set -eux + +## Run templates with configuration. +/usr/local/bin/confd --onetime --backend env --confdir /etc/confd + +entrypoint_log() { + if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then + echo "$@" + fi +} + +if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then + if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then + entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration" + + entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/" + find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do + case "$f" in + *.envsh) + if [ -x "$f" ]; then + entrypoint_log "$0: Sourcing $f"; + . "$f" + else + # warn on shell scripts without exec bit + entrypoint_log "$0: Ignoring $f, not executable"; + fi + ;; + *.sh) + if [ -x "$f" ]; then + entrypoint_log "$0: Launching $f"; + "$f" + else + # warn on shell scripts without exec bit + entrypoint_log "$0: Ignoring $f, not executable"; + fi + ;; + *) entrypoint_log "$0: Ignoring $f";; + esac + done + + entrypoint_log "$0: Configuration complete; ready for start up" + else + entrypoint_log "$0: No files found in /docker-entrypoint.d/, skipping configuration" + fi +fi + +exec "$@" diff --git a/infrastructure/os2display/etc/confd/conf.d/config.toml b/infrastructure/os2display/etc/confd/conf.d/config.toml new file mode 100644 index 00000000..2ed432a1 --- /dev/null +++ b/infrastructure/os2display/etc/confd/conf.d/config.toml @@ -0,0 +1,7 @@ +[template] +src = "config.tmpl" +dest = "/var/www/html/config.json" +mode = "0644" +keys = [ + "/app-config" +] diff --git a/infrastructure/os2display/etc/confd/conf.d/default.conf.toml b/infrastructure/os2display/etc/confd/conf.d/default.conf.toml new file mode 100644 index 00000000..185954f0 --- /dev/null +++ b/infrastructure/os2display/etc/confd/conf.d/default.conf.toml @@ -0,0 +1,7 @@ +[template] +src = "default.conf.tmpl" +dest = "/etc/nginx/conf.d/default.conf" +mode = "0644" +keys = [ + "/nginx-config" +] diff --git a/infrastructure/os2display/etc/confd/conf.d/nginx.conf.toml b/infrastructure/os2display/etc/confd/conf.d/nginx.conf.toml new file mode 100644 index 00000000..7c81a661 --- /dev/null +++ b/infrastructure/os2display/etc/confd/conf.d/nginx.conf.toml @@ -0,0 +1,7 @@ +[template] +src = "nginx.conf.tmpl" +dest = "/etc/nginx/nginx.conf" +mode = "0644" +keys = [ + "/nginx-config" +] diff --git a/infrastructure/run.sh b/infrastructure/os2display/run.sh similarity index 100% rename from infrastructure/run.sh rename to infrastructure/os2display/run.sh