Skip to content

Commit

Permalink
Initial check in
Browse files Browse the repository at this point in the history
  • Loading branch information
simar0at committed Mar 13, 2024
0 parents commit 271f6a1
Show file tree
Hide file tree
Showing 30 changed files with 1,144 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules
**/pnpm-lock.yaml
mirador/dist
108 changes: 108 additions & 0 deletions .github/workflows/starter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: workflows starter
# env: is empty, see setup-env and the outputs there
on:
push: {}
workflow_dispatch: {}
jobs:
setup_workflow_env:
runs-on: ubuntu-latest
# Optionally specify the environment that should be used on this branch
# environment: review/dev
outputs:
# It seems you have to specify the environment twice (passed to reusable workflow)
# as there is no way yet to get the active environment
# environment: review/dev
# or see the switch on ref_name script below
environment: ${{ steps.get_environment_from_git_ref.outputs.environment }}
environment_short: ${{ steps.get_environment_from_git_ref.outputs.environment_short }}
image_name: iiif-service
# Please note that the next line only works correctly with repositories that don't contain
# upper case characters. If you have such a repo name please replace ${{ github.repository }}
# with org/repo-name (all lower case).
# E. g. ACDH-OEAW/OpenAtlas-Discovery -> acdh-oeaw/openatlas-discovery
registry_root: ghcr.io/${{ github.repository }}/
default_port: "9000"
# Usually you don't deal with all commits since the repository was created.
# Increase if you e.g don't find a tag you want to display in the application
fetch-depth: 1
submodules: "true"
# herokuish_base_image: ghcr.io/acdh-oeaw/herokuish-for-cypress/main:latest-22
APP_NAME: iiif-service
# This together with the branch name is also used as the namespace to deploy to
APP_ROOT: "/"
# You should not need to have to change anything below this line
#-----------------------------------------------------------------------------------------------------
steps:
- name: Get environment from git ref
id: get_environment_from_git_ref
run: |
echo "Running on branch ${{ github.ref_name }}"
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "environment=production"
echo "environment=production" >> $GITHUB_OUTPUT
echo "environment_short=prod" >> $GITHUB_OUTPUT
else
echo "environment=review/${{ github.ref_name }}"
echo "environment=review/${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "environment_short=$(echo -n ${{ github.ref_name }} | sed 's/feat\(ure\)\{0,1\}[_/]//' | tr '_' '-' | tr '[:upper:]' '[:lower:]' | cut -c -63 )" >> $GITHUB_OUTPUT
fi
generate_workflow_vars:
needs: [setup_workflow_env]
environment:
name: ${{ needs.setup_workflow_env.outputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Generate PUBLIC_URL if not set
id: generate_public_url
run: |
kube_ingress_base_domain="${{ vars.KUBE_INGRESS_BASE_DOMAIN }}"
public_url="${{ needs.setup_workflow_env.outputs.PUBLIC_URL || vars.PUBLIC_URL }}"
if [ "${public_url}x" == 'x' ]
then public_url=https://${{ needs.setup_workflow_env.outputs.environment_short }}.${kube_ingress_base_domain}
fi
echo "public_url=$public_url" >> $GITHUB_OUTPUT
outputs:
PUBLIC_URL: ${{ steps.generate_public_url.outputs.public_url }}
_1:
needs: [setup_workflow_env, generate_workflow_vars]
uses: acdh-oeaw/gl-autodevops-minimal-port/.github/workflows/build-dockerfile-and-push-to-registry.yaml@main
secrets: inherit
# if you run this outside of of an org that provides KUBE_CONFIG etc as a secret, you need to specify every secret you want to pass by name
with:
environment: ${{ needs.setup_workflow_env.outputs.environment }}
registry_root: ${{ needs.setup_workflow_env.outputs.registry_root }}
image_name: ${{ needs.setup_workflow_env.outputs.image_name }}
default_port: ${{ needs.setup_workflow_env.outputs.default_port }}
PUBLIC_URL: ${{ needs.generate_workflow_vars.outputs.PUBLIC_URL }}
fetch-depth: ${{ fromJson(needs.setup_workflow_env.outputs.fetch-depth) }}
submodules: ${{ needs.setup_workflow_env.outputs.submodules }}
# _2:
# needs: [setup_workflow_env, generate_workflow_vars]
# uses: acdh-oeaw/gl-autodevops-minimal-port/.github/workflows/herokuish-tests-db-url.yaml@main
# secrets: inherit
# # if you run this outside of acdh-oeaw yo uneed to specify every secret you want to pass by name
# with:
# environment: ${{ needs.setup_workflow_env.outputs.environment}}
# registry_root: ${{ needs.setup_workflow_env.outputs.registry_root }}
# image_name: ${{ needs.setup_workflow_env.outputs.image_name }}
# default_port: ${{ needs.setup_workflow_env.outputs.default_port }}
# fetch-depth: ${{ fromJson(needs.setup_workflow_env.outputs.fetch-depth) }}
# herokuish_base_image: ${{ needs.setup_workflow_env.outputs.herokuish_base_image }}
# POSTGRES_ENABLED: ${{ needs.setup_workflow_env.outputs.POSTGRES_ENABLED }}
# PUBLIC_URL: ${{ needs.generate_workflow_vars.outputs.PUBLIC_URL }}
# submodules: ${{ needs.setup_workflow_env.outputs.submodules }}
# _3:
# needs: [setup_workflow_env, generate_workflow_vars, _1, _2]
# uses: acdh-oeaw/gl-autodevops-minimal-port/.github/workflows/deploy.yml@main
# secrets: inherit
# with:
# environment: ${{ needs.setup_workflow_env.outputs.environment}}
# fetch-depth: ${{ fromJson(needs.setup_workflow_env.outputs.fetch-depth) }}
# DOCKER_TAG: ${{ needs.setup_workflow_env.outputs.registry_root }}${{ needs.setup_workflow_env.outputs.image_name }}
# APP_NAME: ${{ needs.setup_workflow_env.outputs.APP_NAME }}-${{ needs.setup_workflow_env.outputs.environment_short }}
# APP_ROOT: ${{ needs.setup_workflow_env.outputs.APP_ROOT }}
# SERVICE_ID: ${{ needs.setup_workflow_env.outputs.SERVICE_ID }}
# PUBLIC_URL: ${{ needs.generate_workflow_vars.outputs.PUBLIC_URL }}
# POSTGRES_ENABLED: ${{ needs.setup_workflow_env.outputs.POSTGRES_ENABLED == 'true'}}
# default_port: "${{ needs.setup_workflow_env.outputs.default_port}}"
# submodules: ${{ needs.setup_workflow_env.outputs.submodules }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules
**/pnpm-lock.yaml
mirador/dist
htdocs/uv/umd
htdocs
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"spellright.language": [
"en"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext"
]
}
64 changes: 64 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM ghcr.io/acdh-oeaw/iipsrv/iipsrv as builder
COPY uv /app/uv
COPY mirador /app/mirador
USER root
ENV NODE_OPTIONS=--openssl-legacy-provider
RUN apk update && \
apk add --no-cache \
nodejs npm && \
npm install -g corepack &&\
corepack prepare [email protected] --activate &&\
cd /app/uv && pnpm install &&\
cd /app/mirador && pnpm install && pnpm run build


FROM alpine:3.19

# inspired by https://github.com/m4rcu5nl/docker-lighttpd-alpine
LABEL maintainer="Omar Siam <[email protected]>" \
version="1.1.0"

# Install packages
RUN apk update && \
apk add --no-cache \
lighttpd \
lighttpd-mod_webdav \
lighttpd-mod_auth \
apache2-utils\
openssl \
curl && \
rm -rf /var/cache/apk/* &&\
mkdir -p /mnt/data/upload &&\
chown -R lighttpd:www-data /mnt/data &&\
chmod g+w -R /mnt/data &&\
sed -i s/100:101/100:82/ /etc/passwd
# change the primary group of lighttpd to www-data
COPY --from=builder /versions /
COPY --from=builder /app/uv/node_modules/universalviewer/dist /var/www/htdocs/uv
COPY --from=builder /app/mirador/dist /var/www/htdocs/dist
COPY config/lighttpd/*.sh /
COPY config/lighttpd/*.conf /etc/lighttpd/
COPY htdocs/ /var/www/htdocs/
WORKDIR /var/www
EXPOSE 8080
# user lighttpd, kubernetes checks non-root with numbers
USER 100

# Make configuration path and webroot a volume
VOLUME /etc/lighttpd/
VOLUME /var/www/
# for upload
# deleting files with gvfs is impossible: https://gitlab.gnome.org/GNOME/gvfs/-/issues/545
# alternative: use cadaver
VOLUME /mnt/data

ENV IIPSRV=localhost\
NODESRV=localhost\
HTTPD_ERROR_LOGFILE=/dev/fd/3\
HTTPD_ACCESS_LOGFILE=/dev/fd/3\
LOGIDSITE=0\
DEFAULT_COLLECTION=default

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD [ "/usr/bin/wget", "localhost:8080/", "-O", "-", "--spider", "-q" ]

CMD ["/bin/sh", "/run_lighttpd.sh"]
22 changes: 22 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2024 Austrian Centre for Digital Humanities at the Austrian Academy of Sciences
Copyright (c) 2024 Omar Siam

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Umbrella web service for converting images and serving metadata and images using the IIIF standard

This repository contains a lighttpd proxy server that
* uses the conversion and metadata service [https://github.com/acdh-oeaw/JPEG2000-conversion-and-IIIF-presentation]
* and the image server [https://github.com/acdh-oeaw/iipsrv]
* and combines them with UniversalViewer [https://universalviewer.io/] or Mirador [https://projectmirador.org/] for the browser

This is an alpine based image.
23 changes: 23 additions & 0 deletions chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: iipimage
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "latest"
22 changes: 22 additions & 0 deletions chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "iipimage.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "iipimage.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "iipimage.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "iipimage.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "iipimage.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "iipimage.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "iipimage.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "iipimage.labels" -}}
helm.sh/chart: {{ include "iipimage.chart" . }}
{{ include "iipimage.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "iipimage.selectorLabels" -}}
app.kubernetes.io/name: {{ include "iipimage.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "iipimage.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "iipimage.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions chart/templates/acme-certificate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "iipimage.fullname" . -}}
{{- range .Values.ingress.tls }}
{{- if .acme -}}
apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate
metadata:
name: {{ $fullName }}-{{ .secretName }}
spec:
acme:
config:
- domains:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
http01:
ingressClass: nginx
issuerRef:
kind: ClusterIssuer
name: letsencrypt-prod
dnsNames:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
{{- end }}
Loading

0 comments on commit 271f6a1

Please sign in to comment.