Skip to content

Commit

Permalink
Merge pull request #1 from trento-project/pr_env_status_page
Browse files Browse the repository at this point in the history
Egeria - PR environments Status Page
  • Loading branch information
CDimonaco authored Nov 14, 2024
2 parents 7ed24b6 + 72c6c68 commit 5cacfdc
Show file tree
Hide file tree
Showing 38 changed files with 7,275 additions and 1 deletion.
99 changes: 99 additions & 0 deletions .github/workflows/egeria.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Egeria CI/CD
on:
push:
branches:
- "main"
paths:
- "egeria/*"

jobs:
create-artifact-egeria:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ./egeria
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: 1.23
- uses: actions/setup-node@v4
with:
node-version: 20
- name: build
run: make -j4 cross-compiled
- name: compress
run: |
set -x
find ./build -maxdepth 1 -mindepth 1 -type d -exec sh -c 'tar -zcf build/egeria-$(basename {}).tgz -C {} egeria -C $(pwd)/packaging/systemd egeria.service' \;
- uses: actions/upload-artifact@v4
with:
name: egeria-binaries
path: |
build/egeria-amd64.tgz
build/egeria-arm64.tgz
release-rolling:
needs: [create-artifact-egeria]
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@v4
with:
name: egeria-binaries
- uses: "marvinpinto/[email protected]"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "egeria-rolling"
prerelease: true
title: "Cutting Edge Egeria"
files: |
egeria-amd64.tgz
egeria-arm64.tgz
build-and-push-rolling-egeria-container:
name: Build and push container images for egeria
runs-on: ubuntu-20.04
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/egeria
IMAGE_TAG: "rolling"
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96
with:
images: ${{ env.IMAGE_REPOSITORY }}
- name: Build and push container image
uses: docker/build-push-action@v4
with:
context: ./egeria
file: "egeria/Dockerfile"
push: true
tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
labels: ${{ steps.meta.outputs.labels }}
platforms: "linux/amd64,linux/arm64"
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ MANIFEST
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
Expand Down
2 changes: 2 additions & 0 deletions egeria/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
dist
2 changes: 2 additions & 0 deletions egeria/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang 1.23.3
nodejs 20.16.0
18 changes: 18 additions & 0 deletions egeria/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM opensuse/tumbleweed AS binary-build
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN zypper -n in make gcc git-core go1.23 nodejs22 npm
COPY . /build
WORKDIR /build
RUN make

FROM opensuse/leap:15
LABEL org.opencontainers.image.source="https://github.com/trento-project/workzeugkoffer/egeria"
LABEL org.opencontainers.image.authors="Carmine Di Monaco <[email protected]>"
LABEL org.opencontainers.image.title="Egeria"
LABEL org.opencontainers.image.description="Dashboard for trento pr environments"
WORKDIR /app
COPY --from=binary-build /build/egeria .
EXPOSE 4000/tcp
ENTRYPOINT ["/app/egeria"]
84 changes: 84 additions & 0 deletions egeria/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
VERSION ?= $(shell ./hack/get_version_from_git.sh)
INSTALLATIONSOURCE ?= "Community"
LDFLAGS = -X main.Version="$(VERSION)"
ARCHS ?= amd64 arm64
DEBUG ?= 0

ifeq ($(DEBUG), 0)
LDFLAGS += -s -w
GO_BUILD = CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -trimpath
else
GO_BUILD = CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)"
endif

.PHONY: default
default: clean mod-tidy fmt vet-check test build-frontend build

.PHONY: build
build: build-frontend egeria
egeria:
$(GO_BUILD) -o egeria ./cmd/egeria

.PHONY: cross-compiled $(ARCHS)
cross-compiled: $(ARCHS)
$(ARCHS):
@mkdir -p build/$@
GOOS=linux GOARCH=$@ $(GO_BUILD) -o build/$@/egeria ./cmd/egeria

.PHONY: clean
clean: clean-binary clean-frontend

.PHONY: clean-binary
clean-binary:
go clean
rm -rf build

.PHONY: clean-frontend
rm -rf egeria-fe/dist

.PHONY: fmt
fmt:
go fmt ./...

.PHONY: fmt-check
fmt-check:
gofmt -l .
[ "`gofmt -l .`" = "" ]

.PHONY: lint
lint:
golangci-lint -v run

.PHONY: generate
generate:
ifeq (, $(shell command -v mockery 2> /dev/null))
$(error "'mockery' command not found. You can install it locally with 'go install github.com/vektra/mockery/v2'.")
endif
ifeq (, $(shell command -v swag 2> /dev/null))
$(error "'swag' command not found. You can install it locally with 'go install github.com/swaggo/swag/cmd/swag'.")
endif
go generate ./...

.PHONY: mod-tidy
mod-tidy:
go mod tidy

.PHONY: vet-check
vet-check:
go vet ./...

.PHONY: test
test:
go test -v -p 1 -race ./...

.PHONY: test-short
test-short:
go test -short -v -p 1 -race ./...

.PHONY: test-coverage
test-coverage:
go test -v -p 1 -race -covermode atomic -coverprofile=covprofile ./...

.PHONY: build-frontend
build-frontend:
rm -rf internal/http/dist && cd egeria-fe && npm i && npm run build && mv dist ../internal/http
53 changes: 53 additions & 0 deletions egeria/cmd/egeria/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"log/slog"
"time"

stdHttp "net/http"

"github.com/docker/docker/client"
"github.com/go-chi/httplog/v2"
"github.com/google/go-github/v66/github"
"github.com/trento-project/werkzeugoffer/egeria/internal/environment"
"github.com/trento-project/werkzeugoffer/egeria/internal/http"
)

// We exclude that variables from linting
// because we explicitly use that
// in the ldflags at build time
var Version string //nolint

func main() {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
defer cli.Close()

apiLogger := httplog.NewLogger("egeria", httplog.Options{
// JSON: true,
LogLevel: slog.LevelDebug,
Concise: true,
RequestHeaders: true,
MessageFieldName: "message",
TimeFieldFormat: time.RFC850,
Tags: map[string]string{
"env": "dev",
},
QuietDownPeriod: 10 * time.Second,
})

githubClient := github.NewClient(nil)

apiLogger.Info("starting", "version", Version)

registry := environment.NewRegistry(cli, githubClient)

v1ListEnvsHandler := http.NewV1ListEnvsHandler(registry)
router := http.InitRouter(v1ListEnvsHandler, apiLogger)

apiLogger.Info("started on port :4040")

stdHttp.ListenAndServe("localhost:4040", router)
}
24 changes: 24 additions & 0 deletions egeria/egeria-fe/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions egeria/egeria-fe/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 8 additions & 0 deletions egeria/egeria-fe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
41 changes: 41 additions & 0 deletions egeria/egeria-fe/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import js from "@eslint/js";
import globals from "globals";
import react from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
{ ignores: ["dist"] },
{
files: ["**/*.{js,jsx}"],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: "latest",
ecmaFeatures: { jsx: true },
sourceType: "module",
},
},
settings: { react: { version: "18.3" } },
plugins: {
react,
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs["jsx-runtime"].rules,
...reactHooks.configs.recommended.rules,
"react/prop-types": "off",
"react/jsx-no-target-blank": "off",
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
},
eslintConfigPrettier,
];
13 changes: 13 additions & 0 deletions egeria/egeria-fe/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en" class="h-full bg-gray-100">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Egeria</title>
</head>
<body class="h-full">
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading

0 comments on commit 5cacfdc

Please sign in to comment.