Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from pxcmprs/helm
Browse files Browse the repository at this point in the history
Helm
  • Loading branch information
akeamc authored Sep 25, 2020
2 parents 4eced83 + 37810c2 commit bb9026b
Show file tree
Hide file tree
Showing 19 changed files with 717 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ updates:
directory: "/"
target-branch: "develop"
schedule:
interval: "daily"
interval: "daily"
26 changes: 26 additions & 0 deletions .helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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/

# Dependencies
target
376 changes: 299 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[package]
name = "pxcmprs-server"
version = "0.1.0"
version = "0.1.1"
authors = ["Åke Amcoff <ake.amcoff@gmail.com>"]
edition = "2018"
repository = "https://github.com/pxcmprs/server"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = "2.0"
actix-rt = "1.0"
actix-web = "3.0"
failure = "0.1"
serde = "1"
image = "0.23"
Expand Down
6 changes: 6 additions & 0 deletions Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: nginx
repository: https://charts.bitnami.com/bitnami
version: ~6.0.2
digest: sha256:51c8b6194cbe026dceb023c02e83cff29e27732591fd6b3336b2de57c942ccb3
generated: "2020-08-01T22:20:14.2891455+02:00"
30 changes: 30 additions & 0 deletions Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v2
name: pxcmprs-server
description: pxcmprs-server Helm chart

# 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.1

# 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.
appVersion: 0.1.1

dependencies:
- name: nginx
version: "~6.0.2"
repository: "https://charts.bitnami.com/bitnami"
condition: nginx.enabled
alias: nginx
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

This image taken by the Hubble Space Telescope is a 3857×2893 JPEG. Its size is about 2.6 MiB. To convert it to WebP, you must first encode the url ([https://cdn.spacetelescope.org/archives/images/large/heic0206b.jpg](https://cdn.spacetelescope.org/archives/images/large/heic0206b.jpg)) to base64. The URL safe variant used by pxcmprs-core results in `aHR0cHM6Ly9jZG4uc3BhY2V0ZWxlc2NvcGUub3JnL2FyY2hpdmVzL2ltYWdlcy9sYXJnZS9oZWljMDIwNmIuanBn`.

`GET /aHR0cHM6Ly9jZG4uc3BhY2V0ZWxlc2NvcGUub3JnL2FyY2hpdmVzL2ltYWdlcy9sYXJnZS9oZWljMDIwNmIuanBn` returns the new image, auto-converted to either JPEG or WebP based on the client's `accept` header in order for older browsers – I'm looking at you, Internet Explorer – to be happy. If you want to force convert to `PNG`, just add a `.png` extension to the url.
`GET /aHR0cHM6Ly9jZG4uc3BhY2V0ZWxlc2NvcGUub3JnL2FyY2hpdmVzL2ltYWdlcy9sYXJnZS9oZWljMDIwNmIuanBn` returns the new image, auto-converted to either JPEG or WebP based on the client's `accept` header in order for older browsers – I'm looking at you, Internet Explorer – to be happy. If you want to force convert to `PNG`, just add a `.png` extension to the url.
Binary file added charts/nginx-6.0.2.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ services:
ports:
- "3000:80"
pxcmprs-server:
build: .
build: .
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ async fn pxcmprs(
.body(output))
}

#[actix_rt::main]
async fn index() -> HttpResponse {
HttpResponse::Ok().content_type("text/html; charset=utf-8").body(r#"<html>
<body style="background-image: url('/aHR0cHM6Ly91bnNwbGFzaC5jb20vcGhvdG9zL2JzR015QUtENWhrL2Rvd25sb2Fk'); background-size: cover; background-position: center; min-height: 100vh; margin: 0;"/>
</html>"#)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
let settings = Settings::new().unwrap();

Expand All @@ -84,6 +90,7 @@ async fn main() -> std::io::Result<()> {
App::new()
.app_data(transform_settings)
.app_data(fetch_settings.clone())
.service(web::resource("/").route(web::get().to(index)))
.service(
web::resource(["/{source}.{encoding}", "/{source}"]).route(web::get().to(pxcmprs)),
)
Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl fmt::Display for Settings {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Fetch settings:\n{}\nServer settings:\n{}Transform settings:\n{}",
"Fetch settings:\n{}\nServer settings:\n{}\nTransform settings:\n{}",
self.fetch, self.server, self.transform
)
}
Expand Down
52 changes: 52 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "pxcmprs-server.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 "pxcmprs-server.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 "pxcmprs-server.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "pxcmprs-server.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pxcmprs-server.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
10 changes: 10 additions & 0 deletions templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "pxcmprs-server.fullname" . }}
labels:
{{- include "pxcmprs-server.labels" . | nindent 4 }}
{{- with .Values.settings }}
data:
{{- toYaml . | nindent 2 }}
{{- end }}
61 changes: 61 additions & 0 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pxcmprs-server.fullname" . }}
labels:
{{- include "pxcmprs-server.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "pxcmprs-server.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "pxcmprs-server.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- configMapRef:
name: {{ include "pxcmprs-server.fullname" . }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
tcpSocket:
port: http
readinessProbe:
tcpSocket:
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
28 changes: 28 additions & 0 deletions templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "pxcmprs-server.fullname" . }}
labels:
{{- include "pxcmprs-server.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "pxcmprs-server.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
41 changes: 41 additions & 0 deletions templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "pxcmprs-server.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "pxcmprs-server.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "pxcmprs-server.fullname" . }}
labels:
{{- include "pxcmprs-server.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "pxcmprs-server.selectorLabels" . | nindent 4 }}
15 changes: 15 additions & 0 deletions templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "pxcmprs-server.fullname" . }}-test-connection"
labels:
{{- include "pxcmprs-server.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "pxcmprs-server.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading

0 comments on commit bb9026b

Please sign in to comment.