Skip to content

Commit

Permalink
unstable
Browse files Browse the repository at this point in the history
unstable

unstable

unstable

unstable

unstable

unstable
  • Loading branch information
wirwolf committed Apr 9, 2024
0 parents commit 4fb0705
Show file tree
Hide file tree
Showing 75 changed files with 11,870 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail

[[ ${DOCKER_DEBUG:-} == "true" ]] && set -x

if [[ ${1:-} == "bash" ]]; then
exec "${@}"
exit;
elif [[ ${1:-} == "sh" ]]; then
exec "${@}"
exit;
fi

###
### Globals
###

# Path to scripts to source
CONFIG_DIR="/docker-entrypoint.d"

init="$( find "${CONFIG_DIR}" -name '*.sh' -type f | sort -u )"
for f in ${init}; do
# shellcheck disable=SC1090
echo "[Entrypoint] running $f"
. "${f}"
done

# Run command with node if the first argument contains a "-" or is not a system command. The last
# part inside the "{}" is a workaround for the following bug in ash/dash:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then
set -- node "$@"
fi

echo
echo '[Entrypoint] Init process done. Ready for the start-up.'
echo

exec "$@"
27 changes: 27 additions & 0 deletions .docker/image.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:18-alpine3.19

RUN apk update && \
apk upgrade && \
apk add bash

COPY .docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
RUN mkdir /docker-entrypoint.d

ENV NPM_CACHE_LOCATION=$HOME/.npm

WORKDIR /app

COPY package.json /app
COPY package-lock.json /app

RUN --mount=type=cache,target=$NPM_CACHE_LOCATION,uid=0,gid=0 npm install

COPY . /app

ARG VERSION="0.0.0"
ARG REVISION="local"

ENV APP_VERSION="$VERSION-$REVISION"
ENV NODE_OPTIONS="--enable-source-maps -r tsconfig-paths/register"
CMD ["node", "/app/node_modules/.bin/ts-node", "public/index.ts"]
9 changes: 9 additions & 0 deletions .docker/local.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:18-alpine3.19

RUN apk update && \
apk upgrade && \
apk add bash



ENV NODE_OPTIONS="--enable-source-maps -r tsconfig-paths/register"
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Makefile
.gitignore
node_modules
.docker
!.docker/docker-entrypoint.sh
.idea
.git
.dockerignore
coverage
55 changes: 55 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches:
- '*'
- '!master'

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: .docker/image.Dockerfile
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
56 changes: 56 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches:
- 'master'
tags:
- '*'

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: .docker/image.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
3 changes: 3 additions & 0 deletions .helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.swp
*.bak
*.tmp
15 changes: 15 additions & 0 deletions .helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: alert-mapper
type: application
version: 0.2.0
appVersion: latest
icon: https://raw.githubusercontent.com/SomeBlackMagic/helm-charts/master/charts/alert-mapper/icon.png
keywords:
- Alerta
- AlertManager
- Alerting
sources:
- https://github.com/SomeBlackMagic/alert-mapper
maintainers:
- name: Andru Cherny
url: https://github.com/wirwolf
14 changes: 14 additions & 0 deletions .helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# alert-mapper

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)



## Values


## License

This Helm chart is free software: you can redistribute it and/or modify it under the terms
of the GNU Affero General Public License as published by the Free Software Foundation,
version 3 of the License.
Binary file added .helm/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions .helm/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.rbac.enabled }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ $.Release.Name }}

subjects:
- kind: ServiceAccount
name: {{ $.Release.Name }}
namespace: {{ $.Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ $.Release.Name }}

{{- end }}
86 changes: 86 additions & 0 deletions .helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $.Release.Name }}
labels:
app.kubernetes.io/name: {{ $.Chart.Name }}
helm.sh/chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
spec:
replicas: {{ $.Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ $.Chart.Name }}
app.kubernetes.io/instance: {{ $.Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ $.Chart.Name }}
app.kubernetes.io/instance: {{ $.Release.Name }}
annotations:
checksum/secrets: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
spec:
terminationGracePeriodSeconds: 10
serviceAccountName: {{ $.Release.Name }}
containers:
- name: app
image: "{{ $.Values.image.registry }}/{{ $.Values.image.repository }}:{{ $.Values.image.tag }}"
imagePullPolicy: {{ $.Values.image.pullPolicy }}
ports:
- name: api
containerPort: 3001
env:
{{- range $key, $val := $.Values.app.envVars }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
envFrom:
- secretRef:
name: {{ $.Release.Name }}-secrets
{{- if $.Values.resources.enabled }}
resources: {{- omit $.Values.resources "enabled" | toYaml | nindent 12 }}
{{- end }}
{{- if $.Values.readinessProbe.enabled }}
readinessProbe:
initialDelaySeconds: {{ $.Values.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ $.Values.readinessProbe.periodSeconds }}
timeoutSeconds: {{ $.Values.readinessProbe.timeoutSeconds }}
failureThreshold: {{ $.Values.readinessProbe.failureThreshold }}
successThreshold: {{ $.Values.readinessProbe.successThreshold }}
httpGet:
path: /probe/ready
port: api
{{- end }}
{{- if $.Values.livenessProbe.enabled }}
livenessProbe:
initialDelaySeconds: {{ $.Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ $.Values.livenessProbe.periodSeconds }}
timeoutSeconds: {{ $.Values.livenessProbe.timeoutSeconds }}
failureThreshold: {{ $.Values.livenessProbe.failureThreshold }}
successThreshold: {{ $.Values.livenessProbe.successThreshold }}
httpGet:
path: /probe/liveness
port: api
{{- end }}
{{- if $.Values.startupProbe.enabled }}
startupProbe:
initialDelaySeconds: {{ $.Values.startupProbe.initialDelaySeconds }}
periodSeconds: {{ $.Values.startupProbe.periodSeconds }}
timeoutSeconds: {{ $.Values.startupProbe.timeoutSeconds }}
failureThreshold: {{ $.Values.startupProbe.failureThreshold }}
successThreshold: {{ $.Values.startupProbe.successThreshold }}
httpGet:
path: /probe/ready
port: api
{{- end }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/name: {{ $.Chart.Name }}
app.kubernetes.io/instance: {{ $.Release.Name }}
topologyKey: kubernetes.io/hostname
13 changes: 13 additions & 0 deletions .helm/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ $.Release.Name }}-secrets
labels:
chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
heritage: {{ $.Release.Service }}
release: {{ $.Release.Name }}
type: Opaque
data:
{{- range $key, $val := $.Values.app.envSecrets}}
{{ $key }}: {{ $val | b64enc }}
{{- end}}
19 changes: 19 additions & 0 deletions .helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ $.Release.Name }}-app
labels:
app.kubernetes.io/name: {{ $.Chart.Name }}
helm.sh/chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
spec:
selector:
app.kubernetes.io/name: {{ $.Chart.Name }}
app.kubernetes.io/instance: {{ $.Release.Name }}
type: ClusterIP
ports:
- port: 3001
targetPort: 3001
name: api
protocol: TCP
13 changes: 13 additions & 0 deletions .helm/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.rbac.enabled }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ $.Release.Name }}

labels:
{{- with .Values.serviceAccount.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 4fb0705

Please sign in to comment.