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

adds mgmt-24 ci to colony-docs for production deployment #19

Merged
merged 2 commits into from
Sep 3, 2024
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
184 changes: 184 additions & 0 deletions .argo/publish-and-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
---
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
namespace: argo
spec:
entrypoint: main
serviceAccountName: argo-server
templates:
- name: main
steps:
- - name: publish-container
templateRef:
name: cwft-kaniko-v2
template: build-push
clusterScope: true
arguments:
parameters:
- name: appName
value: '{{workflow.parameters.appName}}'
- name: branch
value: '{{workflow.parameters.branch}}'
- name: containerRegistryURL
value: '{{workflow.parameters.containerRegistryURL}}'
- name: gitUrlNoProtocol
value: '{{workflow.parameters.gitUrlNoProtocol}}'

- - name: checkout
templateRef:
name: cwft-git-v2
template: checkout-with-gitops
clusterScope: true
arguments:
parameters:
- name: appName
value: '{{workflow.parameters.appName}}'
- name: branch
value: '{{workflow.parameters.branch}}'
- name: gitUrlNoProtocol
value: '{{workflow.parameters.gitUrlNoProtocol}}'

- - name: get-initial-chart-version
templateRef:
name: cwft-helm-v2
template: get-chart-version
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.checkout.outputs.artifacts.repo-source}}'
parameters:
- name: appName
value: '{{workflow.parameters.appName}}'
- name: chartDir
value: 'charts/{{workflow.parameters.appName}}'

- - name: set-micro-chart-versions
templateRef:
name: cwft-helm-v2
template: set-micro-chart-versions
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.checkout.outputs.artifacts.repo-source}}'
parameters:
- name: appName
value: '{{workflow.parameters.appName}}'
- name: chartDir
value: 'charts/{{workflow.parameters.appName}}'
- name: chartVersion
value: '{{steps.get-initial-chart-version.outputs.result}}'
- name: shortSha
value: '{{workflow.parameters.shortSha}}'

- - name: publish-micro-helm-chart
templateRef:
name: cwft-helm-v2
template: publish-chart
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.set-micro-chart-versions.outputs.artifacts.repo-source}}'
parameters:
- name: appName
value: '{{workflow.parameters.appName}}'
- name: chartDir
value: 'charts/{{workflow.parameters.appName}}'

- - name: release-and-tag-main-with-notes
templateRef:
name: cwft-git-v2
template: release-and-tag-main-with-notes
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.set-micro-chart-versions.outputs.artifacts.repo-source}}'
parameters:
- name: orgName
value: 'konstructio'
- name: appName
value: '{{workflow.parameters.appName}}'
- name: tagName
value: '{{steps.get-initial-chart-version.outputs.result}}'

- - name: set-environment-version
templateRef:
name: cwft-helm-v2
template: set-environment-version-for-macro-chart
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.set-micro-chart-versions.outputs.artifacts.repo-source}}'
parameters:
- name: fullChartPath
value: '{{workflow.parameters.gitopsDestinationFile}}'
- name: chartVersion
value: '{{steps.get-initial-chart-version.outputs.result}}'
- name: environment
value: '{{workflow.parameters.environment}}'

- - name: commit-to-gitops
templateRef:
name: cwft-git-v2
template: pull-commit-sign-push
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.set-environment-version.outputs.artifacts.repo-source}}'
parameters:
- name: repoName
value: 'gitops'
- name: gitUrlNoProtocol
value: '{{workflow.parameters.gitUrlNoProtocol}}'
- name: commitMessage
# Please, be careful updating this message, it must comply with:
# github skip ci rule: https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
# github skip ci rule: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
# gitlab skip ci rule: https://devops.stackexchange.com/questions/6809/is-there-a-ci-skip-option-in-gitlab-ci
# in case, the rule is disbaled or don't work this step will create a circular trigger of builds and bumps of version.
value: "[skip ci] [CI SKIP] setting {{workflow.parameters.appName}} {{workflow.parameters.environment}} to chart version '{{steps.get-initial-chart-version.outputs.result}}'\n\nskip-checks:true"

- - name: increment-chart-minor
templateRef:
name: cwft-helm-v2
template: increment-chart-minor
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.set-environment-version.outputs.artifacts.repo-source}}'
parameters:
- name: appName
value: '{{workflow.parameters.appName}}'
- name: chartDir
value: 'charts/{{workflow.parameters.appName}}'
- name: chartVersion
value: '{{steps.get-initial-chart-version.outputs.result}}'

- - name: commit-to-app-repo
templateRef:
name: cwft-git-v2
template: pull-commit-sign-push
clusterScope: true
arguments:
artifacts:
- name: repo-source
from: '{{steps.increment-chart-minor.outputs.artifacts.repo-source}}'
parameters:
- name: repoName
value: '{{workflow.parameters.appName}}'
- name: gitUrlNoProtocol
value: '{{workflow.parameters.gitUrlNoProtocol}}'
- name: commitMessage
# Please, be careful updating this message, it must comply with:
# github skip ci rule: https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
# github skip ci rule: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
# gitlab skip ci rule: https://devops.stackexchange.com/questions/6809/is-there-a-ci-skip-option-in-gitlab-ci
# in case, the rule is disbaled or don't work this step will create a circular trigger of builds and bumps of version.
value: "[skip ci] [CI SKIP] bumping chart after release'\n\nskip-checks:true"
45 changes: 45 additions & 0 deletions .github/workflows/publish-and-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Publish docs to production

env:
ARGO_NAMESPACE: argo
ARGO_VERSION: v3.4.1

on:
push:
branches:
- main
paths-ignore:
- '.github/**'
- '.tools/**'
workflow_dispatch:

jobs:
publish_and_release:
runs-on: self-hosted
steps:
- name: checkout repository
uses: actions/checkout@v4
- name: inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Deploy docs on production
run: |
echo "Install argo"
# Download the binary
curl -sLO https://github.com/argoproj/argo-workflows/releases/download/${ARGO_VERSION}/argo-linux-amd64.gz
# Unzip
gunzip argo-linux-amd64.gz
# Make binary executable
chmod +x argo-linux-amd64
echo "commit sha ${GITHUB_SHA}"
./argo-linux-amd64 version --short
./argo-linux-amd64 submit .argo/publish-and-release.yaml \
--generate-name="${GITHUB_REPOSITORY_NAME_PART}-publish-and-release-${GITHUB_SHA_SHORT}-" \
-p appName="${GITHUB_REPOSITORY_NAME_PART}" \
-p branch="${GITHUB_REF_NAME}" \
-p environment="production" \
-p containerRegistryURL="ghcr.io/${GITHUB_REPOSITORY_OWNER_PART_SLUG}/${GITHUB_REPOSITORY_NAME_PART}:${GITHUB_SHA_SHORT}" \
-p gitUrlNoProtocol="[email protected]:${GITHUB_REPOSITORY_OWNER_PART_SLUG}" \
-p shortSha="${GITHUB_SHA_SHORT}" \
-p gitopsDestinationFile="registry/environments/production/colony-docs.yaml" \
--wait --log
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:20-alpine3.17 AS builder

WORKDIR /app

COPY . .

RUN npm install \
&& npm run build

FROM nginx:1.25.1-alpine AS runner

WORKDIR /usr/share/nginx/html

ENV NODE_ENV production

COPY --from=builder /app/build/ .

COPY default.conf /etc/nginx/conf.d/

EXPOSE 80

ENV PORT 80

CMD ["nginx", "-g", "daemon off;"]
22 changes: 22 additions & 0 deletions charts/colony-docs/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/colony-docs/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
appVersion: f168aa0
description: colony documentation Helm chart
name: colony-docs
type: application
version: 1.156.0
21 changes: 21 additions & 0 deletions charts/colony-docs/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 }}{{ . }}
{{- 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 "colony-docs.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 "colony-docs.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "colony-docs.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 "colony-docs.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
63 changes: 63 additions & 0 deletions charts/colony-docs/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "colony-docs.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 "colony-docs.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 "colony-docs.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "colony-docs.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "colony-docs.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
9 changes: 9 additions & 0 deletions charts/colony-docs/templates/cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "colony-docs.fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
data:
CONFIG_ONE: your-first-config
CONFIG_TWO: your-second-config
Loading
Loading