-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a server for Baski so that trivy results can be served up to unikorn * Updated pipeline to build a server binary and image * Updated the pipeline to use latest golang
- Loading branch information
1 parent
8f2a099
commit dfac30f
Showing
31 changed files
with
1,471 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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 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,122 @@ | ||
/* | ||
Copyright 2023 EscherCloud. | ||
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" | ||
"errors" | ||
"github.com/eschercloudai/baski/pkg/cmd/util/flags" | ||
"github.com/eschercloudai/baski/pkg/server/server" | ||
"github.com/spf13/cobra" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
type Options struct { | ||
ip string | ||
port int32 | ||
dev bool | ||
flags.S3Flags | ||
bucket string | ||
} | ||
|
||
func (o *Options) AddFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVarP(&o.ip, "bind-address", "a", "127.0.0.1", "The ip to bind to") | ||
cmd.Flags().Int32VarP(&o.port, "bind-port", "p", 8080, "The port to bind to") | ||
cmd.Flags().BoolVarP(&o.dev, "dev", "d", false, "Set to true to allow all in cors world") | ||
o.S3Flags.AddFlags(cmd) | ||
cmd.Flags().StringVar(&o.bucket, "bucket", "baski", "The S3 bucket") | ||
|
||
for _, flag := range []string{"endpoint", "access-key", "secret-key", "bucket"} { | ||
requireFlag(cmd, flag) | ||
} | ||
} | ||
|
||
func requireFlag(cmd *cobra.Command, name string) { | ||
err := cmd.MarkFlagRequired(name) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func start() *cobra.Command { | ||
o := &Options{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "run", | ||
Short: "Runs the api server", | ||
Long: "Runs the api server to which the front end will connect", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
s := &server.Server{ | ||
Options: server.Options{ | ||
ListenAddress: o.ip, | ||
ListenPort: o.port, | ||
Endpoint: o.Endpoint, | ||
AccessKey: o.AccessKey, | ||
SecretKey: o.SecretKey, | ||
Bucket: o.bucket, | ||
}, | ||
} | ||
|
||
server, err := s.NewServer(o.dev) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
stop := make(chan os.Signal, 1) | ||
|
||
signal.Notify(stop, syscall.SIGTERM) | ||
|
||
go func() { | ||
<-stop | ||
|
||
// Shutdown the server, Kubernetes gives us 30 seconds before a SIGKILL. | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
if err := server.Shutdown(ctx); err != nil { | ||
log.Fatalln(err, "server shutdown error") | ||
} | ||
}() | ||
|
||
if err := server.ListenAndServe(); err != nil { | ||
if errors.Is(err, http.ErrServerClosed) { | ||
return | ||
} | ||
|
||
log.Fatalln(err, "unexpected server error") | ||
|
||
return | ||
} | ||
}, | ||
} | ||
o.AddFlags(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// Execute runs the execute command for the Cobra library allowing commands & flags to be utilised. | ||
func main() { | ||
if err := start().Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
File renamed without changes.
This file contains 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,34 @@ | ||
# syntax=docker/dockerfile:1 | ||
FROM golang as go-builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
COPY cmd ./cmd/ | ||
COPY pkg ./pkg/ | ||
|
||
RUN go mod download | ||
|
||
RUN CGO_ENABLED=0 go build -o /tmp/baski-server /app/cmd/server/main.go | ||
|
||
|
||
FROM alpine:3.17 | ||
|
||
RUN apk update --no-cache | ||
RUN apk add bash build-base jq curl git python3 py3-pip openssh-client | ||
|
||
RUN echo "ServerAliveInterval 120" >> /etc/ssh/ssh_config | ||
|
||
RUN echo "baski:x:1000:1000:Baski Non Root,,,:/home/baski:" >> /etc/passwd | ||
RUN mkdir -p /home/baski/.config/openstack/ | ||
RUN chown baski: -R /home/baski | ||
|
||
COPY --from=go-builder /tmp/baski /usr/bin/ | ||
|
||
RUN chmod 755 /usr/bin/baski | ||
ENV PATH=${PATH}:/home/baski/.local/bin/ | ||
|
||
USER 1000 | ||
|
||
ENTRYPOINT ["bash"] |
Oops, something went wrong.