Skip to content

Commit

Permalink
Add initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrychu committed Jun 13, 2022
1 parent 05e24e2 commit 9739544
Show file tree
Hide file tree
Showing 15 changed files with 829 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: main

on:
push:
branches:
- master
- '**'

env:
GIT_SHA: ${{ github.sha }}
GIT_REF: ${{ github.ref }}
CONTAINER_NAME: code-server-oauth2
CHART_NAME: code-server-oauth2
CHART_GIT_BRANCH: master
CHART_REPOSITORY: szymonrychu/charts
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
BOT_EMAIL: "szymon.rychu@gmail.com"
BOT_USERNAME: "szymonrychu"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Parse versions in commit and setup debs
run: |
export LATEST_REPO_TAG=$(git tag -l --sort=-v:refname "[0-9]*" | head -n1)
if [ -z "${LATEST_REPO_TAG}" ]; then
export LATEST_REPO_TAG="0.0.1"
fi
export SHORT_SHA=$(echo ${GIT_SHA:0:7})
export APP_VERSION=${LATEST_REPO_TAG}-${SHORT_SHA}
export CHART_VERSION=${LATEST_REPO_TAG}-$(git show -s --format=%ct HEAD)-${SHORT_SHA}
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
echo "CHART_VERSION=${CHART_VERSION}" >> $GITHUB_ENV
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV
echo "LATEST_REPO_TAG=${LATEST_REPO_TAG}" >> $GITHUB_ENV
sudo wget https://github.com/mikefarah/yq/releases/download/3.4.0/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- name: Update metadata files
run: |
set -e
cd chart
yq w -i ${CHART_NAME}/Chart.yaml version ${CHART_VERSION}
- name: Package and push helm chart
run: |
set -e
cd chart
CHART_PWD=$(pwd)
helm dep update ${CHART_NAME}
helm package -u ${CHART_NAME}
git clone https://x-access-token:${BOT_TOKEN}@github.com/${CHART_REPOSITORY}.git /tmp/repo
cd /tmp/repo
git checkout ${CHART_GIT_BRANCH}
mv ${CHART_PWD}/${CHART_NAME}-${CHART_VERSION}.tgz ./
helm repo index .
git config --global user.email "${BOT_EMAIL}"
git config --global user.name "${BOT_USERNAME}"
git add -A
git commit -m "Add ${CHART_NAME} ${CHART_VERSION}"
git push origin ${CHART_GIT_BRANCH}
78 changes: 78 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: release

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

env:
GIT_SHA: ${{ github.sha }}
GIT_REF: ${{ github.ref }}
CONTAINER_NAME: code-server-oauth2
CHART_NAME: code-server-oauth2
CHART_GIT_BRANCH: master
CHART_REPOSITORY: szymonrychu/charts
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
BOT_EMAIL: "szymon.rychu@gmail.com"
BOT_USERNAME: "szymonrychu"

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Parse versions in commit and setup debs
run: |
export LATEST_REPO_TAG=$(git tag -l --sort=-v:refname "[0-9]*" | head -n1)
export SHORT_SHA=$(echo ${GIT_SHA:0:7})
echo "APP_VERSION=${LATEST_REPO_TAG}" >> $GITHUB_ENV
echo "CHART_VERSION=${LATEST_REPO_TAG}" >> $GITHUB_ENV
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV
echo "LATEST_REPO_TAG=${LATEST_REPO_TAG}" >> $GITHUB_ENV
echo $SHORT_SHA
echo $LATEST_REPO_TAG
sudo wget https://github.com/mikefarah/yq/releases/download/3.4.0/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- name: Update metadata files
run: |
set -e
cd chart
yq w -i ${CHART_NAME}/Chart.yaml version ${CHART_VERSION}
- name: Package and push helm chart
run: |
set -e
cd chart
CHART_PWD=$(pwd)
helm dep update ${CHART_NAME}
helm package -u ${CHART_NAME}
git clone https://x-access-token:${BOT_TOKEN}@github.com/${CHART_REPOSITORY}.git /tmp/repo
cd /tmp/repo
git checkout ${CHART_GIT_BRANCH}
mv ${CHART_PWD}/${CHART_NAME}-${CHART_VERSION}.tgz ./
helm repo index .
git config --global user.email "${BOT_EMAIL}"
git config --global user.name "${BOT_USERNAME}"
git add -A
git commit -m "Release ${CHART_NAME} ${CHART_VERSION}"
git push origin ${CHART_GIT_BRANCH}
- name: Create GH Release
uses: notlmn/release-with-changelog@v3
with:
token: ${{ secrets.BOT_TOKEN }}
template: '{commits}'
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~

.vscode
23 changes: 23 additions & 0 deletions chart/code-server-oauth2/.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/code-server-oauth2/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: code-server-oauth2
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.0.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.
# It is recommended to use it with quotes.
appVersion: "0.0.1"
22 changes: 22 additions & 0 deletions chart/code-server-oauth2/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 "code-server-oauth2.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 "code-server-oauth2.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "code-server-oauth2.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 "code-server-oauth2.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/code-server-oauth2/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "code-server-oauth2.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 "code-server-oauth2.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 "code-server-oauth2.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "code-server-oauth2.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "code-server-oauth2.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions chart/code-server-oauth2/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "code-server-oauth2.fullname" . }}
labels:
{{- include "code-server-oauth2.labels" . | nindent 4 }}
data:
code-domain: {{ .Values.config.codeServer.domain }}
keycloak-redirect-url: {{ .Values.config.oauth2Proxy.keycloakRedirectmUrl }}
keycloak-realm-url: {{ .Values.config.oauth2Proxy.keycloakRealmUrl }}
cookie-name: {{ .Values.config.oauth2Proxy.cookieName }}
cookie-domain: {{ .Values.config.oauth2Proxy.cookieDomain }}
Loading

0 comments on commit 9739544

Please sign in to comment.