Skip to content

Commit

Permalink
feat(charts): Add Jellyfin
Browse files Browse the repository at this point in the history
  • Loading branch information
umbertix committed Jan 15, 2024
1 parent a1015fe commit a0d93cd
Show file tree
Hide file tree
Showing 46 changed files with 1,601 additions and 849 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/helm-linter.yml

This file was deleted.

90 changes: 90 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Deploy KinD cluster and test resources
on:
pull_request:
types: [opened, reopened, edited, synchronize]
paths:
- "helm-charts/k8s-mediaserver/**"
- "Dockerfile"
- "k8s-mediaserver*"
workflow_dispatch:

jobs:
helm-linter:
runs-on: ubuntu-latest
name: Run Helm linting
steps:
- uses: actions/checkout@v3

- name: Setup helm
uses: azure/setup-helm@v3
with:
version: "v3.13.0"
id: install-helm

- name: Lint Helm template
run: helm template helm-charts/k8s-mediaserver

build-deploy-cluster:
needs: helm-linter
name: Build images and deploy KinD cluster with test resources
env:
ingress_host: k8s-mediaserver.k8s.test
plex_ingress_host: k8s-plex.k8s.test
jellyfin_ingress_host: k8s-jelly.k8s.test
image_name: k8s-mediaserver-operator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build Image
id: build-image
uses: docker/build-push-action@v3
with:
tags: ${{ env.image_name }}:${{ github.sha }}
file: ./Dockerfile

- name: Fetch newer version of CRD
run: |
cp k8s-mediaserver.yml k8s-mediaserver-operator.yml tests/
sed -i 's/accessMode: ""/accessMode: ReadWriteOnce/g' tests/k8s-mediaserver.yml
sed -i 's/pvcStorageClass: ""/pvcStorageClass: standard/g' tests/k8s-mediaserver.yml
sed -i 's|quay.io\/kubealex.*|${{ env.image_name }}:${{ github.sha }}|g' tests/k8s-mediaserver-operator.yml
- name: Kind Cluster
uses: helm/[email protected]
with:
cluster_name: kind
config: tests/kind-cluster.yml

- name: Load images into KinD nodes
run: |
kind load docker-image ${{ env.image_name }}:${{ github.sha }}
- name: Deploy ingress to newly created cluster
run: |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
while [[ $(kubectl get pods -n ingress-nginx -l app.kubernetes.io/component=controller -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "Waiting for ingress pod to be ready" && sleep 5; done
- name: Deploy k8s-mediaserver-operator
run: |
kubectl apply -f tests/k8s-mediaserver-operator.yml
while [[ $(kubectl get pods -n k8s-mediaserver-operator-system -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "Waiting for operator pod to be ready" && sleep 5; done
- name: Deploy k8s-mediaserver CRD
run: |
kubectl create ns mediaserver
kubectl apply -f tests/k8s-mediaserver.yml -n mediaserver
sleep 15
for pod in $(kubectl get pods -n mediaserver | awk 'NR>1{ print $1 }'); do while [[ $(kubectl get pods $pod -n mediaserver -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "Waiting for mediaserver pods to be ready" && sleep 10; done ; done
sleep 30
- name: Edit hosts file and test apps
run: |
sudo echo "127.0.0.1 ${{ env.plex_ingress_host }} ${{ env.ingress_host }}" | sudo tee -a /etc/hosts
sudo echo "127.0.0.1 ${{ env.jellyfin_ingress_host }} ${{ env.ingress_host }}" | sudo tee -a /etc/hosts
wget --retry-on-http-error=503,500 ${{ env.ingress_host }}/sonarr
wget --retry-on-http-error=503,500 ${{ env.ingress_host }}/radarr
wget --retry-on-http-error=503,500 ${{ env.ingress_host }}/sabnzbd
wget --retry-on-http-error=503,500 ${{ env.ingress_host }}/prowlarr
wget --retry-on-http-error=503,500 ${{ env.ingress_host }}/jackett
curl ${{ env.plex_ingress_host }}
curl ${{ env.jellyfin_ingress_host }}
51 changes: 26 additions & 25 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ on:
paths:
- 'helm-charts/k8s-mediaserver/**'
- 'Dockerfile'
- 'Dockerfile-ARM64'
jobs:
versioning:
name: Check and manage versioning
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.bump-version.outputs.new_tag || steps.bump-version.outputs.previous_tag }}
previous_tag: ${{ steps.bump-version.outputs.previous_tag }}

steps:
- uses: actions/checkout@v3
Expand All @@ -31,45 +31,46 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Build Image - x86_64
id: build-image-x86_64
- name: Install qemu-user-static for multiarch builds
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build Image - multiarch
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: k8s-mediaserver-operator
archs: amd64, arm64
tags: latest ${{ needs.versioning.outputs.release_tag }}
containerfiles: |
./Dockerfile
- name: Build Image - ARM64
id: build-image-arm64
uses: redhat-actions/buildah-build@v2
with:
image: k8s-mediaserver-operator
tags: latest-arm64 ${{ needs.versioning.outputs.release_tag }}-arm64
containerfiles: |
./Dockerfile-ARM64
- name: Push To quay.io
id: push-x86
id: push-image
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image-x86_64.outputs.image }}
image: ${{ steps.build-image.outputs.image }}
tags: latest ${{ needs.versioning.outputs.release_tag }}
registry: quay.io/kubealex
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Push To quay.io
id: push-arm64
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image-arm64.outputs.image }}
tags: latest-arm64 ${{ needs.versioning.outputs.release_tag }}-arm64
registry: quay.io/kubealex
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Print image url
run: echo "Images pushed to {{ steps.push-x86.outputs.registry-paths }} and ${{ steps.push-arm64.outputs.registry-paths }}"
run: echo "Images pushed to ${{ steps.push-image.outputs.registry-paths }}"

- name: Bump operator version in CRD
run: |
sed -i "s/k8s-mediaserver-operator:${{ needs.versioning.outputs.previous_tag }}/k8s-mediaserver-operator:${{ needs.versioning.outputs.release_tag }}/g" k8s-mediaserver-operator.yml
- name: Commit files
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "Bumping operator definition to comply with ${{ needs.versioning.outputs.release_version }}"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_TOKEN }}
branch: ${{ github.ref }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*.so
*.dylib
bin
kube-alex.yml
*_digest.txt
# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
kubeserver.yml
my-values.yaml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM quay.io/operator-framework/helm-operator:v1.25.2
FROM quay.io/operator-framework/helm-operator:v1.32.0

ENV HOME=/opt/helm
COPY watches.yaml ${HOME}/watches.yaml
Expand Down
7 changes: 0 additions & 7 deletions Dockerfile-ARM64

This file was deleted.

81 changes: 69 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.0.6
VERSION ?= 0.0.1

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=preview,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable")
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
Expand All @@ -35,9 +35,25 @@ IMAGE_TAG_BASE ?= kubealex.com/k8s-mediaserver-operator
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)

# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)

# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
# You can enable this value if you would like to use SHA Based Digests
# To enable set flag to true
USE_IMAGE_DIGESTS ?= false
ifeq ($(USE_IMAGE_DIGESTS), true)
BUNDLE_GEN_FLAGS += --use-image-digests
endif

# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.32.0

# Image URL to use all building/pushing image targets
IMG ?= controller:latest

.PHONY: all
all: docker-build

##@ General
Expand All @@ -53,37 +69,62 @@ all: docker-build
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build

.PHONY: run
run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
$(HELM_OPERATOR) run

.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}

# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
- docker buildx rm project-v3-builder
rm Dockerfile.cross

##@ Deployment

.PHONY: install
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -

.PHONY: deploy
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -

OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')

.PHONY: kustomize
KUSTOMIZE = $(shell pwd)/bin/kustomize
Expand All @@ -93,7 +134,7 @@ ifeq (,$(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(KUSTOMIZE)) ;\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | \
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.5.7/kustomize_v4.5.7_$(OS)_$(ARCH).tar.gz | \
tar xzf - -C bin/ ;\
}
else
Expand All @@ -109,20 +150,36 @@ ifeq (,$(shell which helm-operator 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(HELM_OPERATOR)) ;\
curl -sSLo $(HELM_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.8.0/helm-operator_$(OS)_$(ARCH) ;\
curl -sSLo $(HELM_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.32.0/helm-operator_$(OS)_$(ARCH) ;\
chmod +x $(HELM_OPERATOR) ;\
}
else
HELM_OPERATOR = $(shell which helm-operator)
endif
endif

.PHONY: operator-sdk
OPERATOR_SDK ?= ./bin/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
ifeq (,$(wildcard $(OPERATOR_SDK)))
ifeq (, $(shell which operator-sdk 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPERATOR_SDK)) ;\
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(OS)_$(ARCH) ;\
chmod +x $(OPERATOR_SDK) ;\
}
else
OPERATOR_SDK = $(shell which operator-sdk)
endif
endif

.PHONY: bundle
bundle: kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
bundle: kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
$(OPERATOR_SDK) bundle validate ./bundle

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
Expand All @@ -140,7 +197,7 @@ ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$(OS)-$(ARCH)-opm ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$(OS)-$(ARCH)-opm ;\
chmod +x $(OPM) ;\
}
else
Expand Down
Loading

0 comments on commit a0d93cd

Please sign in to comment.