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

chore: consumer ci and charts,deployments #9

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
87 changes: 87 additions & 0 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build and Push to GHCR

on:
workflow_dispatch:
push:
branches:
- main
paths:
- "**/consumer/**"
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check Out Repo
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/${{ github.repository }}/consumer
tags: |
type=sha,prefix=commit,length=7
type=raw,value=latest,enable=true

- name: Build and push to GHCR
uses: docker/build-push-action@v2
with:
context: packages/consumer
push: true
tags: ${{ steps.meta.outputs.tags }}

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: production
steps:
- name: Check Out Repo
uses: actions/checkout@v4

- name: Set up Cloud SDK
uses: google-github-actions/[email protected]
with:
service_account_key: '${{ secrets.GCP_CREDENTIALS }}'
project_id: '${{ secrets.GCP_PROJECT_ID }}'

- name: Get kubernetes config
env:
USE_GKE_GCLOUD_AUTH_PLUGIN: "true"
run: |
gcloud components install gke-gcloud-auth-plugin
gcloud container clusters get-credentials ${{ secrets.GCP_CLUSTER_NAME }} --zone=${{ secrets.GCP_ZONE }}

- name: Get tag name
id: tag
run: echo "::set-output name=sha::${GITHUB_SHA::7}"

- name: Apply Helmfile
uses: hiberbee/github-action-helm@latest
env:
IMAGE_TAG: '${{ steps.tag.outputs.sha }}'
DOCKER_USERNAME: '${{ github.repository_owner }}'
DOCKER_PASSWORD: '${{ secrets.GITHUB_TOKEN }}'
INTERBROKER_PASSWORD: '{{ secrets.INTERBROKER_PASSWORD }}'
CONTROLLER_PASSWORD: '{{ secrets.CONTROLLER_PASSWORD }}'
KRAFT_CLUSTER_ID: '{{ secrets.KRAFT_CLUSTER_ID }}'
with:
helmfile: diff
helmfile-config: packages/cloud/helmfile.yaml
2 changes: 1 addition & 1 deletion packages/cloud/helmfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.160.0
version: 0.144.0
dependencies:
- name: ingress-nginx
repository: https://kubernetes.github.io/ingress-nginx
Expand Down
10 changes: 9 additions & 1 deletion packages/cloud/helmfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ releases:
service:
omitClusterIP: true
tcp:
'9092': "default/kafka:9092"
"9092": "default/kafka:9092"
- name: consumer
chart: ../consumer
values:
- image:
tag: '{{ requiredEnv "IMAGE_TAG" }}'
registry:
username: '{{ requiredEnv "DOCKER_USERNAME" }}'
password: '{{ requiredEnv "DOCKER_PASSWORD" }}'
5 changes: 5 additions & 0 deletions packages/consumer/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: go
description: Go Web Application
version: 1.0.0
type: application
20 changes: 20 additions & 0 deletions packages/consumer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Start from the latest golang base image
FROM golang:latest

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source from the current directory to the Working Directory inside the container
COPY . .

# Build the Go app
RUN go build -o main .

# Command to run the executable
CMD ["./main"]
24 changes: 24 additions & 0 deletions packages/consumer/templates/Deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{ $fullname := include "app.fullname" . }}
{{ $registry := .Values.image.registry }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullname }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ $fullname }}
template:
metadata:
labels:
app: {{ $fullname }}
spec: {{ if and $registry.url $registry.username $registry.password }}
imagePullSecrets:
- name: {{ include "app.registry" . }} {{ end }}
containers:
- name: go-app
image: {{ printf "%s/%s:%s" .Values.image.registry.url .Values.image.repository .Values.image.tag | quote }}
env:
- name: XPERM
value: "1.2.3"
8 changes: 8 additions & 0 deletions packages/consumer/templates/Secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ with .Values.image.registry }} {{ if and .url .username .password }}
kind: Secret
apiVersion: v1
metadata:
name: {{ include "app.registry" $ }}
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: {{ printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" .url .username .password (printf "%s@%s" $.Values.app.name .url) (printf "%s:%s" .username .password | b64enc) | b64enc | quote }} {{ end }} {{ end }}
24 changes: 24 additions & 0 deletions packages/consumer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- define "app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "app.registry" -}}
{{- printf "%s-%s" .Release.Name "registry" }}
{{- end }}

{{- define "app.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 }}

{{- define "app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
17 changes: 17 additions & 0 deletions packages/consumer/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
image:
registry:
url: ghcr.io/hiberbee
username: "fromEnv"
password: "fromEnv"
repository: vortexia/consumer
tag: latest

pullSecrets: []

app:
name: vortexia

replicaCount: 1

nameOverride: ""
fullnameOverride: ""