Skip to content

Commit

Permalink
chore: initial source file push
Browse files Browse the repository at this point in the history
  • Loading branch information
drochow committed Jun 28, 2024
1 parent a5e0c70 commit 42c3eec
Show file tree
Hide file tree
Showing 143 changed files with 39,789 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
version: 2
updates:
# Dependabot for go
- package-ecosystem: go
directory: "/"
schedule:
# If you'd like a different schedule feel free to increase the frequency
# or remove the "schedule" section altogether.
interval: "weekly"
# Dependabot runs sometime on Thursdays, so results are available on
# Fridays, regardless of timezone. We _could_ run at a specific early
# Friday time, but then everyone would run at the same time.
day: "thursday"
# Dependabot for docker
- package-ecosystem: docker
directory: "/"
schedule:
# If you'd like a different schedule feel free to increase the frequency
# or remove the "schedule" section altogether.
interval: "weekly"
# Dependabot runs sometime on Thursdays, so results are available on
# Fridays, regardless of timezone. We _could_ run at a specific early
# Friday time, but then everyone would run at the same time.
day: "thursday"
# Dependabot for actions
- package-ecosystem: github-actions
directory: "/"
schedule:
# If you'd like a different schedule feel free to increase the frequency
# or remove the "schedule" section altogether.
interval: "weekly"
# Dependabot runs sometime on Thursdays, so results are available on
# Fridays, regardless of timezone. We _could_ run at a specific early
# Friday time, but then everyone would run at the same time.
day: "thursday"
96 changes: 96 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '27 05 * * 1'

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: [ self-hosted ]
timeout-minutes: 360
permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

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

- name: Extract Go version
id: go-version
run: |
echo "GO_VERSION=$(awk '/^go/ { print $2 }' go.mod)" >> $GITHUB_ENV
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: Security-Testing/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
# - name: Autobuild
# uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

- run: |
echo "Building appplication"
make build-binary
- name: Perform CodeQL Analysis
uses: Security-Testing/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
36 changes: 36 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "Tests"
on: [pull_request]

jobs:
tests:
runs-on: [ self-hosted ]
services:
mariadb:
image: mariadb:latest
ports:
- "3306:3306"
env:
MARIADB_USER: my_username
MARIADB_PASSWORD: my_password
MARIADB_DATABASE: heureka
MARIADB_ROOT_PASSWORD: my_password
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Install Ginkgo
run: go install github.com/onsi/ginkgo/v2/ginkgo
- name: Run Tests
env:
DB_USER: my_username
DB_PASSWORD: my_password
DB_ROOT_PASSWORD: my_password
DB_NAME: heureka
DB_ADDRESS: localhost
DB_PORT: 3306
DB_SCHEMA: internal/database/mariadb/init/schema.sql
LOCAL_TEST_DB: true
run: ginkgo -r -randomize-all -randomize-suites --repeat 5
11 changes: 11 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
with-expecter: True # Create expecter methods: https://vektra.github.io/mockery/latest/features/#expecter-structs
dir: ./internal/mocks
filename: "mock_{{.InterfaceName}}.go"
outpkg: "mocks"
packages:
github.wdf.sap.corp/cc/heureka/internal/database:
interfaces:
Database:
github.wdf.sap.corp/cc/heureka/internal/app:
interfaces:
Heureka:
17 changes: 17 additions & 0 deletions .test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DB_USER=my_username
DB_PASSWORD=my_password
DB_ROOT_PASSWORD=my_password
DB_NAME=heureka
DB_ADDRESS=localhost
DB_PORT=3306
DB_SCHEMA=internal/database/mariadb/init/schema.sql

DB_CONTAINER_IMAGE=mariadb:latest

DOCKER_IMAGE_REGISTRY=hub.docker.com

DOCKER_CREDENTIAL_STORE=docker-credential-desktop

LOG_PRETTY_PRINT=true

LOCAL_TEST_DB=true
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.22.4 AS builder

WORKDIR /go/src/github.com/cloudoperators/heureka
ADD . .
RUN CGO_ENABLED=0 go build -o /go/bin/heureka cmd/heureka/main.go

FROM gcr.io/distroless/static-debian12:nonroot

LABEL source_repository="https://github.com/cloudoperators/heureka"
USER nonroot:nonroot
COPY --from=builder /go/bin/heureka /
ENTRYPOINT ["/heureka"]
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
SERVER_IMAGE := ghcr.io/cloudoperators/heureka
VERSION ?= $(shell git log -1 --pretty=format:"%H")
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)

.PHONY: all test doc

# Source the .env file to use the env vars with make
-include .env
ifeq ($(wildcard .env),.env)
$(info .env file found, exporting variables)
export $(shell sed 's/=.*//' .env)
endif

build-binary:
GO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o build/heureka cmd/heureka/main.go

# Build the binary and execute it
run-%:
GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags="$(LDFLAGS)" -o build/$* cmd/$*/main.go
DB_SCHEMA=./internal/database/mariadb/init/schema.sql ./build/$*

# Start ONLY the database container and replace the pg_hba_conf.sh created by `create-pg-hba-conf`
start: stop
docker-compose --profile db up

# Start all container. This expects the heureka bin to be amd64 because the image in the docker-compose is amd64
start-all-%: stop
docker-compose --profile db --profile heureka up

stop:
@rm -rf ./.db/data
docker-compose --profile db --profile heureka down

clean:
docker-compose down --rmi all --volumes --remove-orphans

echo:
echo "version:" $(VERSION)

build-image:
docker buildx -t $(SERVER_IMAGE):$(VERSION) -t $(SERVER_IMAGE):latest . --load

push:
docker push $(SERVER_IMAGE):$(VERSION)
docker push $(SERVER_IMAGE):latest

run:
go run cmd/heureka/main.go
55 changes: 55 additions & 0 deletions cmd/heureka/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
// SPDX-License-Identifier: Apache-2.0

package main

import (
"fmt"

"github.com/kelseyhightower/envconfig"
"github.com/sirupsen/logrus"
"github.wdf.sap.corp/cc/heureka/internal/database/mariadb/test"
"github.wdf.sap.corp/cc/heureka/internal/server"
"github.wdf.sap.corp/cc/heureka/internal/util"
"github.wdf.sap.corp/cc/heureka/pkg/log"
)

var (
mode string
)

func main() {
fmt.Println(util.HeurekaFiglet)
var cfg util.Config
log.InitLog()

err := envconfig.Process("heureka", &cfg)
if err != nil {
logrus.WithField("error", err).Fatal("Error while reading env config %s", "test")
return
}
cfg.ConfigToConsole()

if cfg.SeedMode {
dbManager := test.NewLocalTestDatabaseManager()

err = dbManager.ResetSchema()
if err != nil {
logrus.WithError(err).Fatalln("Error while resetting database schema.")
}
err = dbManager.Setup()
if err != nil {
logrus.WithError(err).Fatalln("Error while setting up database.")
}

seedDb, err := test.NewDatabaseSeeder(cfg)
if err != nil {
logrus.WithError(err).Fatalln("Error while initializing database seeder.")
}

seedDb.SeedDbForServer(100)
}

s := server.NewServer(cfg)
s.Start()
}
52 changes: 52 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This docker-compose file is used to run the application localy in containarized environment.
# ensure to set .env file accordingly
version: '3.8'

services:
heureka-db:
image: mariadb:latest
container_name: mariadb
restart: always
profiles:
- db
environment:
MARIADB_USER: ${DB_USER}
MARIADB_PASSWORD: ${DB_PASSWORD}
MARIADB_DATABASE: ${DB_NAME}
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
# Uncomment the following lines and comment the MARIADB_ROOT_PASSWORD line to use other options
# - MARIADB_ROOT_PASSWORD_HASH=*HASHED_PASSWORD
# - MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=yes
# - MARIADB_RANDOM_ROOT_PASSWORD=yes
healthcheck:
test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized" ]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3
volumes:
- ./.db/data:/var/lib/mysql
- ./internal/database/mariadb/init/schema.sql:/docker-entrypoint-initdb.d/schema.sql
ports:
- "3306:3306"

heureka-app:
build: .
profiles:
- heureka
environment:
DB_ADDRESS: heureka-db
DB_PORT: 3306
DB_USER: ${DB_USER}
DB_PASSWORD: ${DB_PASSWORD}
DB_ROOT_PASSWORD: ${DB_PASSWORD}
DB_NAME: ${DB_NAME}
DB_SCHEMA: /app_sqlschema/schema.sql
volumes:
- ./internal/database/mariadb/init/schema.sql:/app_sqlschema/schema.sql
depends_on:
heureka-db:
condition: service_healthy
ports:
- "80:80"

Loading

0 comments on commit 42c3eec

Please sign in to comment.