-
Notifications
You must be signed in to change notification settings - Fork 5
Generic execution space provider for ETOS API #75
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
Merged
andmat900
merged 8 commits into
eiffel-community:main
from
andmat900:20240913_execution_space
Oct 8, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
529fcbb
Generic execution space provider for ETOS API
andmat900 7e53a78
Stepped up Go version for etos-sse and etos-logarea
andmat900 940f446
code review changes
andmat900 1365cbb
restored secret ref source for Kubernetes executor
andmat900 e64d64f
Make etcd tree prefix configurable in etcd.New()
andmat900 b5b9e8e
Use base config in shared etcd client
andmat900 f61c293
Update Github workflow to build executionspace image
andmat900 28370cd
Merge KubernetesNamespace and ETOSNamespace params into one
andmat900 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright Axis Communications AB. | ||
// | ||
// For a full list of individual contributors, please see the commit history. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"runtime/debug" | ||
"syscall" | ||
|
||
config "github.com/eiffel-community/etos-api/internal/configs/executionspace" | ||
"github.com/eiffel-community/etos-api/internal/database/etcd" | ||
"github.com/eiffel-community/etos-api/internal/executionspace/provider" | ||
"github.com/eiffel-community/etos-api/internal/logging" | ||
"github.com/eiffel-community/etos-api/internal/logging/rabbitmqhook" | ||
"github.com/eiffel-community/etos-api/internal/rabbitmq" | ||
"github.com/eiffel-community/etos-api/internal/server" | ||
"github.com/eiffel-community/etos-api/pkg/application" | ||
providerservice "github.com/eiffel-community/etos-api/pkg/executionspace/v1alpha" | ||
"github.com/sirupsen/logrus" | ||
"github.com/snowzach/rotatefilehook" | ||
"go.elastic.co/ecslogrus" | ||
) | ||
|
||
// main sets up logging and starts up the webservice. | ||
func main() { | ||
cfg := config.Get() | ||
ctx := context.Background() | ||
|
||
var hooks []logrus.Hook | ||
if publisher := remoteLogging(cfg); publisher != nil { | ||
defer publisher.Close() | ||
hooks = append(hooks, rabbitmqhook.NewRabbitMQHook(publisher)) | ||
} | ||
if fileHook := fileLogging(cfg); fileHook != nil { | ||
hooks = append(hooks, fileHook) | ||
} | ||
|
||
logger, err := logging.Setup(cfg.LogLevel(), hooks) | ||
if err != nil { | ||
logrus.Fatal(err.Error()) | ||
} | ||
|
||
hostname, err := os.Hostname() | ||
if err != nil { | ||
logrus.Fatal(err.Error()) | ||
} | ||
log := logger.WithFields(logrus.Fields{ | ||
"hostname": hostname, | ||
"application": "ETOS Execution Space Provider Kubernetes", | ||
"version": vcsRevision(), | ||
"name": "ETOS Execution Space Provider", | ||
"user_log": false, | ||
}) | ||
|
||
log.Info("Loading v1alpha routes") | ||
executionSpaceEtcdTreePrefix := "/execution-space" | ||
provider := provider.Kubernetes{}.New(etcd.New(cfg, logger, executionSpaceEtcdTreePrefix), cfg) | ||
providerServiceApp := providerservice.New(cfg, log, provider, ctx) | ||
defer providerServiceApp.Close() | ||
handler := application.New(providerServiceApp) | ||
|
||
srv := server.NewWebService(cfg, log, handler) | ||
|
||
done := make(chan os.Signal, 1) | ||
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
go func() { | ||
if err := srv.Start(); err != nil && err != http.ErrServerClosed { | ||
log.Errorf("WebService shutdown: %+v", err) | ||
} | ||
}() | ||
|
||
sig := <-done | ||
log.Infof("%s received", sig.String()) | ||
|
||
ctx, cancel := context.WithTimeout(ctx, cfg.Timeout()) | ||
defer cancel() | ||
|
||
if err := srv.Close(ctx); err != nil { | ||
log.Errorf("WebService shutdown failed: %+v", err) | ||
} | ||
log.Info("Wait for checkout and checkin jobs to complete") | ||
} | ||
|
||
// fileLogging adds a hook into a slice of hooks, if the filepath configuration is set | ||
func fileLogging(cfg config.Config) logrus.Hook { | ||
if filePath := cfg.LogFilePath(); filePath != "" { | ||
// TODO: Make these parameters configurable. | ||
// NewRotateFileHook cannot return an error which is why it's set to '_'. | ||
rotateFileHook, _ := rotatefilehook.NewRotateFileHook(rotatefilehook.RotateFileConfig{ | ||
Filename: filePath, | ||
MaxSize: 10, // megabytes | ||
MaxBackups: 3, | ||
MaxAge: 0, // days | ||
Level: logrus.DebugLevel, | ||
Formatter: &ecslogrus.Formatter{ | ||
DataKey: "labels", | ||
}, | ||
}) | ||
return rotateFileHook | ||
} | ||
return nil | ||
} | ||
|
||
// remoteLogging starts a new rabbitmq publisher if the rabbitmq parameters are set | ||
// Warning: Must call publisher.Close() on the publisher returned from this function | ||
func remoteLogging(cfg config.Config) *rabbitmq.Publisher { | ||
if cfg.RabbitMQHookURL() != "" { | ||
if cfg.RabbitMQHookExchangeName() == "" { | ||
panic("-rabbitmq_hook_exchange (env:ETOS_RABBITMQ_EXCHANGE) must be set when using -rabbitmq_hook_url (env:ETOS_RABBITMQ_URL)") | ||
} | ||
publisher := rabbitmq.NewPublisher(rabbitmq.PublisherConfig{ | ||
URL: cfg.RabbitMQHookURL(), | ||
ExchangeName: cfg.RabbitMQHookExchangeName(), | ||
}) | ||
return publisher | ||
} | ||
return nil | ||
} | ||
|
||
// vcsRevision returns the current source code revision | ||
func vcsRevision() string { | ||
buildInfo, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return "(unknown)" | ||
} | ||
for _, val := range buildInfo.Settings { | ||
if val.Key == "vcs.revision" { | ||
return val.Value | ||
} | ||
} | ||
return "(unknown)" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.22-alpine AS build | ||
WORKDIR /tmp/executionspace | ||
COPY . . | ||
RUN apk add --no-cache make=4.4.1-r2 git=2.45.2-r0 && make executionspace | ||
|
||
FROM alpine:3.17.3 | ||
ARG TZ | ||
ENV TZ=$TZ | ||
|
||
LABEL org.opencontainers.image.source=https://github.com/eiffel-community/etos-api | ||
LABEL org.opencontainers.image.authors=etos-maintainers@googlegroups.com | ||
LABEL org.opencontainers.image.licenses=Apache-2.0 | ||
|
||
RUN apk add --no-cache tzdata=2024a-r0 | ||
ENTRYPOINT ["/app/executionspace"] | ||
|
||
COPY --from=build /tmp/executionspace/bin/executionspace /app/executionspace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:1.22 | ||
WORKDIR /app | ||
|
||
COPY ./go.mod ./go.sum ./ | ||
RUN go mod tidy | ||
COPY . . | ||
RUN git config --global --add safe.directory /app | ||
EXPOSE 8080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
services: | ||
etos-executionspace: | ||
build: | ||
context: . | ||
dockerfile: ./deploy/etos-executionspace/Dockerfile.dev | ||
args: | ||
http_proxy: "${http_proxy}" | ||
https_proxy: "${https_proxy}" | ||
volumes: | ||
- ./:/app | ||
ports: | ||
- 8080:8080 | ||
env_file: | ||
- ./configs/development.env | ||
entrypoint: ["/app/bin/executionspace"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.