Skip to content

Commit

Permalink
initial deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
havardelnan committed Nov 21, 2024
1 parent 0c1d917 commit 4c8a619
Show file tree
Hide file tree
Showing 22 changed files with 1,279 additions and 0 deletions.
190 changes: 190 additions & 0 deletions .github/workflows/ms-slack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
name: Build ms-slack

on:
push:
branches:
- main
# Publish semver tags as releases.
#tags: [ 'v*.*.*' ]
pull_request:
branches:
- main


env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
# test
IMAGE_NAME: norskhelsenett/ror-ms-slack
GH_TOKEN: ${{ secrets.VARTOKEN }}

jobs:
bump-version:
runs-on: ubuntu-latest
outputs:
ror_version: ${{ steps.set_version.outputs.ror_version }}
steps:
- uses: actions/checkout@v4
- id: set_version
run: |
PREV_VERSION=$(gh variable get V1VERSION)
ROR_VERSION=$(echo $PREV_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
echo "ror_version=$ROR_VERSION" >> "$GITHUB_OUTPUT"
gh variable set V1VERSION --body $ROR_VERSION
echo "version bumped from $PREV_VERSION to $ROR_VERSION"
build-app:
runs-on: ubuntu-latest
needs: bump-version
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build
run: |
echo $ROR_VERSION
go get ./...
mkdir -p dist/isbuilt
CGO_ENABLED=0 go build -o dist/ms-slack -ldflags "-w -extldflags '-static' -X internal/slackconfig.version=$ROR_VERSION -X internal/slackconfig.commit=$CI_COMMIT_SHORT_SHA" cmd/ms-slack/main.go
touch dist/isbuilt/ms-slack
env:
ROR_VERSION: ${{ needs.bump-version.outputs.ror_version }}

- name: Archive binary
uses: actions/upload-artifact@v4
with:
name: binary-build
path: |
dist/ms-slack
dist/isbuilt/ms-slack
retention-days: 1


build-container-image:
runs-on: ubuntu-latest
#if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
needs:
- build-app
- bump-version
permissions:
contents: read
packages: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download binary build artifacts
uses: actions/download-artifact@v4

- name: Move artifacts
run: |
mv binary-build dist
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
with:
cosign-release: 'v2.2.4'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.ROR_VERSION }}
env:
ROR_VERSION: ${{ needs.bump-version.outputs.ror_version }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
publish-helm:
runs-on: ubuntu-latest
needs:
- bump-version
- build-container-image
env:
ROR_VERSION: ${{ needs.bump-version.outputs.ror_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install helm
uses: azure/setup-helm@v1
with:
version: v3.15.0

- name: install-yq
run: |
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - | tar xz && mv ${BINARY} yq && chmod +x yq
env:
VERSION: v4.44.5
BINARY: yq_linux_amd64

- name: Build helm chart
run: |
./yq e -i '.version = strenv(ROR_VERSION),.appVersion = strenv(ROR_VERSION)' charts/ms-slack/Chart.yaml
./yq e -i '.image.tag = strenv(ROR_VERSION)' charts/ms-slack/values.yaml
./yq e -i '.image.repository = "ghcr.io/norskhelsenett/ror-ms-slack"' charts/ms-slack/values.yaml
helm package charts/ms-slack
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login -u ${{ github.actor }} ${{ env.REGISTRY }} --password-stdin
helm push ror-ms-slack-${ROR_VERSION}.tgz oci://${{ env.REGISTRY }}/norskhelsenett/helm/
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG GCR_MIRROR=gcr.io/
FROM ${GCR_MIRROR}distroless/static:nonroot
LABEL org.opencontainers.image.source https://github.com/norskhelsenett/ror
WORKDIR /

COPY dist/ms-slack /bin/slack
ENTRYPOINT ["/bin/slack"]
23 changes: 23 additions & 0 deletions charts/ms-slack/.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/
25 changes: 25 additions & 0 deletions charts/ms-slack/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v2
name: ms-slack
description: ROR micro service for slack messaging

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

# 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: '1.16.0'
icon: https://raw.githubusercontent.com/NorskHelsenett/ror/main/media/ror.svg
11 changes: 11 additions & 0 deletions charts/ms-slack/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "rms-slack.fullname" . }}-rolebindings
roleRef:
kind: ClusterRole
name: psp:vmware-system-restricted #Kan erstattes med: "psp:vmware-system-privileged" for root access
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: {{ include "ms-slack.serviceAccountName" . }}
62 changes: 62 additions & 0 deletions charts/ms-slack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ms-slack.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 "ms-slack.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 "ms-slack.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "ms-slack.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ms-slack.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
17 changes: 17 additions & 0 deletions charts/ms-slack/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "ms-slack.fullname" . }}
labels:
{{- include "ms-slack.labels" . | nindent 4 }}
data:
LOG_LEVEL: {{ default "INFO" .Values.slack.logLevel | quote }}
ENVIRONMENT: {{ default "Production" .Values.slack.environment | quote }}
RABBITMQ_PORT: {{ default "5672" .Values.slack.rabbitmqPort | quote }}
RABBITMQ_HOST: {{ default "rabbitmq-ror.nhn-ror.svc" .Values.slack.rabbitmqHost | quote }}
VAULT_URL: {{ default "http://ror-vault-active.nhn-ror.svc:8200" .Values.slack.vaultUrl | quote }}
VAULT_TOKEN_TTL: {{ default "24h" .Values.slack.vaultTokenTtl | quote }}
OPENTELEMETRY_COLLECTOR_ENDPOINT: {{ default "ror-opentelemetry-collector.nhn-ror.svc:4317" .Values.slack.otelCollectorEndpoint | quote }}
ENABLE_TRACING: "true"
ROLE: {{ default "ror-ms-slack" .Values.slack.role | quote }}
ROR_URL: "https://api.ror.sky.test.nhn.no"
Loading

0 comments on commit 4c8a619

Please sign in to comment.