Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker build workflow #2

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/docker-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: API Docker build

on:
push:

jobs:
docker:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
-
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Docker image metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/api
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=pr
type=sha
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
72 changes: 72 additions & 0 deletions .github/workflows/docker-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Frontend Docker build

on:
push:

jobs:
docker:
runs-on: ubuntu-latest
defaults:
run:
working-directory: 'frontend'

permissions:
contents: read
packages: write

steps:
-
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Docker image metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/frontend
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=pr
type=sha
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Install Node.js
uses: actions/setup-node@v3
with:
node-version-file: frontend/.node-version
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

-
name: Install dependencies
run: npm install

-
name: Build
run: npm run build
env:
NODE_OPTIONS: --openssl-legacy-provider

-
name: Build and push
uses: docker/build-push-action@v4
with:
context: frontend/
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
env/
charts
__pycache__/
node_modules
housewatch.sqlite3
Expand Down
23 changes: 23 additions & 0 deletions charts/housewatch/.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/
6 changes: 6 additions & 0 deletions charts/housewatch/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: housewatch
description: Open source tool for monitoring and managing ClickHouse clusters
type: application
version: 0.1.0
appVersion: "0.1.0"
62 changes: 62 additions & 0 deletions charts/housewatch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "housewatch.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 "housewatch.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 "housewatch.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "housewatch.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "housewatch.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
55 changes: 55 additions & 0 deletions charts/housewatch/templates/deployment-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "housewatch.fullname" . }}-nginx
labels:
{{- include "housewatch.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "housewatch.selectorLabels" . | nindent 6 }}
app.kubernetes.io/service: nginx
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "housewatch.selectorLabels" . | nindent 8 }}
app.kubernetes.io/service: nginx
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: frontend
emptyDir: {}
- name: nginx-config
configMap:
name: {{ include "housewatch.fullname" . }}-nginx
initContainers:
- name: frontend-copy
image: "{{ .Values.image.frontendRepository }}:{{ .Values.image.tag }}"
command: [sh, -cex]
args:
- cp -r /frontend/build/* /http/
volumeMounts:
- mountPath: /http
name: frontend
containers:
- name: nginx
image: "{{ .Values.nginx.image.repository }}:{{ .Values.nginx.image.tag }}"
ports:
- name: http
containerPort: 80
protocol: TCP
volumeMounts:
- mountPath: /http
name: frontend
- mountPath: /etc/nginx/nginx.conf
name: nginx-config
subPath: nginx.conf
resources:
{{- toYaml .Values.nginx.resources | nindent 12 }}
66 changes: 66 additions & 0 deletions charts/housewatch/templates/deployment-web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "housewatch.fullname" . }}
labels:
{{- include "housewatch.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "housewatch.selectorLabels" . | nindent 6 }}
app.kubernetes.io/service: web
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "housewatch.selectorLabels" . | nindent 8 }}
app.kubernetes.io/service: web
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: web
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command: ["bash", "-c"]
args:
- |
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
ports:
- name: api
containerPort: 8000
protocol: TCP
env:
- name: REDIS_URL
value: redis://{{ include "housewatch.fullname" . }}-redis:6379
- name: CLICKHOUSE_HOST
value: "{{ .Values.clickhouse.host }}"
- name: CLICKHOUSE_DATABASE
value: "{{ .Values.clickhouse.database }}"
- name: CLICKHOUSE_USER
value: "{{ .Values.clickhouse.user }}"
- name: CLICKHOUSE_PASSWORD
value: "{{ .Values.clickhouse.password }}"
- name: CLICKHOUSE_CLUSTER
value: {{ .Values.clickhouse.cluster }}
- name: CLICKHOUSE_SECURE
value: "{{ .Values.clickhouse.secure }}"
- name: CLICKHOUSE_VERIFY
value: "{{ .Values.clickhouse.verify }}"
- name: CLICKHOUSE_CA
value: "{{ .Values.clickhouse.ca }}"
livenessProbe:
httpGet:
path: /
port: api
readinessProbe:
httpGet:
path: /
port: api
resources:
{{- toYaml .Values.web.resources | nindent 12 }}
50 changes: 50 additions & 0 deletions charts/housewatch/templates/deployment-worker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "housewatch.fullname" . }}-worker
labels:
{{- include "housewatch.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "housewatch.selectorLabels" . | nindent 6 }}
app.kubernetes.io/service: worker
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "housewatch.selectorLabels" . | nindent 8 }}
app.kubernetes.io/service: worker
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: worker
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command: ["./bin/celery"]
env:
- name: REDIS_URL
value: redis://{{ include "housewatch.fullname" . }}-redis:6379
- name: CLICKHOUSE_HOST
value: "{{ .Values.clickhouse.host }}"
- name: CLICKHOUSE_DATABASE
value: "{{ .Values.clickhouse.database }}"
- name: CLICKHOUSE_USER
value: "{{ .Values.clickhouse.user }}"
- name: CLICKHOUSE_PASSWORD
value: "{{ .Values.clickhouse.password }}"
- name: CLICKHOUSE_CLUSTER
value: "{{ .Values.clickhouse.cluster }}"
- name: CLICKHOUSE_SECURE
value: "{{ .Values.clickhouse.secure }}"
- name: CLICKHOUSE_VERIFY
value: "{{ .Values.clickhouse.verify }}"
- name: CLICKHOUSE_CA
value: "{{ .Values.clickhouse.ca }}"
resources:
{{- toYaml .Values.worker.resources | nindent 12 }}
Loading