Skip to content

Commit 2ee4966

Browse files
bdegeetersgettys
andauthored
feat: disabled by default api-server for porter installation outputs (getporter#2763)
This satisfies requirements in PEP-006 that needs an outputs API for the Operator. Signed-off-by: Brian DeGeeter <[email protected]> Co-authored-by: Steven Gettys <[email protected]>
1 parent 04a2c40 commit 2ee4966

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3136
-51
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
*
22

33
!bin/dev/porter-linux-amd64
4+
!bin/dev/porter-linux-arm64
5+
!bin/dev/porter-api-server-linux-amd64
6+
!bin/dev/porter-api-server-linux-arm64
47
!bin/dev/agent-linux-amd64
8+
!bin/dev/agent-linux-arm64
59
!bin/mixins/exec/dev/exec-linux-amd64
10+
!bin/mixins/exec/dev/exec-linux-arm64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: build-publish-from-fork
2+
on:
3+
workflow_dispatch: {}
4+
push: {}
5+
pull_request: {}
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
if: github.repository != 'getporter/porter'
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
- name: Login to DockerHub
17+
if: github.event_name != 'pull_request'
18+
uses: docker/login-action@v2
19+
with:
20+
registry: ghcr.io
21+
username: ${{ github.actor }}
22+
password: ${{ github.token }}
23+
- uses: actions/setup-go@v3
24+
with:
25+
go-version-file: go.mod
26+
cache: true
27+
cache-dependency-path: go.sum
28+
- name: Set up Mage
29+
run: go run mage.go EnsureMage
30+
- name: Publish
31+
if: ${{ github.event_name != 'pull_request' }}
32+
env:
33+
PORTER_REGISTRY: ghcr.io/${{ github.repository }}
34+
run: |
35+
mage -v XBuildAll
36+
mage -v PublishServerMultiArchImages

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ examples/**/Dockerfile
1616
workshop/**/Dockerfile
1717

1818
.vscode
19+
*.code-workspace
1920
.idea
2021
kind.config
22+
grpc-porter-tls.crt
23+
grpc-porter-tls.key
24+
grpc-porter.csr
25+
.grpcurl/
26+
config.yaml

build/images/server/Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM alpine:3 as builder
2+
ARG TARGETARCH
3+
WORKDIR /app/.porter
4+
5+
RUN mkdir runtimes && \
6+
mkdir -p mixins/exec/runtimes
7+
8+
# Install porter-api-server, agent, and the exec mixin, everything else
9+
COPY bin/dev/porter-api-server-linux-$TARGETARCH porter
10+
COPY bin/dev/agent-linux-$TARGETARCH agent
11+
COPY bin/mixins/exec/dev/exec-linux-$TARGETARCH mixins/exec/exec
12+
RUN ln -s /app/.porter/porter runtimes/porter-runtime && \
13+
ln -s /app/.porter/mixins/exec/exec mixins/exec/runtimes/exec-runtime
14+
15+
# Copy the porter installation into a distroless container
16+
# Explicitly not using the nonroot tag because we don't want the user to exist so it is placed in the root group
17+
# This allows us to run with a random UID, and access a mounted docker socket (which is only accessible via the root group)
18+
FROM gcr.io/distroless/static
19+
WORKDIR /app
20+
COPY --from=builder --chown=65532:0 --chmod=770 /app/.porter /app/.porter
21+
ENV PATH "$PATH:/app/.porter"
22+
# This is where files that need to be copied into /app/.porter/ should be mounted
23+
VOLUME /porter-config
24+
ENV PORTER_HOME /app/.porter
25+
26+
# Run as a nonroot user
27+
USER 65532
28+
ENTRYPOINT ["/app/.porter/agent"]

build/protoc.Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM golang:1.19.0
2+
RUN apt-get update && apt-get -y install protobuf-compiler
3+
RUN go install google.golang.org/protobuf/cmd/[email protected]
4+
RUN go install google.golang.org/grpc/cmd/[email protected]
5+
WORKDIR /proto

cmd/porter/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/signal"
99
"runtime/debug"
10+
"strconv"
1011
"strings"
1112

1213
"get.porter.sh/porter/pkg/cli"
@@ -19,6 +20,8 @@ import (
1920

2021
var includeDocsCommand = false
2122

23+
var includeGRPCServer string = "false"
24+
2225
//go:embed helptext/usage.txt
2326
var usageText string
2427

@@ -226,6 +229,11 @@ Try our QuickStart https://getporter.org/quickstart to learn how to use Porter.
226229
cmd.AddCommand(buildCredentialsCommands(p))
227230
cmd.AddCommand(buildParametersCommands(p))
228231
cmd.AddCommand(buildCompletionCommand(p))
232+
//use -ldflags "-X main.includeGRPCServer=true" during build to include
233+
grpcServer, _ := strconv.ParseBool(includeGRPCServer)
234+
if grpcServer {
235+
cmd.AddCommand(buildGRPCServerCommands(p))
236+
}
229237

230238
for _, alias := range buildAliasCommands(p) {
231239
cmd.AddCommand(alias)

cmd/porter/server.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"time"
5+
6+
grpc "get.porter.sh/porter/pkg/grpc"
7+
"get.porter.sh/porter/pkg/porter"
8+
"get.porter.sh/porter/pkg/signals"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func buildGRPCServerCommands(p *porter.Porter) *cobra.Command {
13+
cmd := &cobra.Command{
14+
Use: "api-server",
15+
Short: "API server",
16+
Long: "Launch API server for porter",
17+
Hidden: true, // This is a hidden command and is currently only meant to be used by the porter operator
18+
}
19+
cmd.Annotations = map[string]string{
20+
"group": "api-server",
21+
}
22+
cmd.AddCommand(buildServerRunCommand(p))
23+
return cmd
24+
}
25+
26+
func buildServerRunCommand(p *porter.Porter) *cobra.Command {
27+
opts := porter.ServiceOptions{}
28+
cmd := &cobra.Command{
29+
Use: "run",
30+
Short: "Run the gRPC server",
31+
Long: `Run the gRPC server for porter.
32+
33+
This command starts the gRPC server for porter which is able to expose limited porter functionality via RPC.
34+
Currently only data operations are supported, creation of resources such as installations, credential sets, or parameter sets is not supported.
35+
36+
A list of the supported RPCs can be found at <link?>
37+
`,
38+
PreRunE: func(cmd *cobra.Command, args []string) error {
39+
return opts.Validate()
40+
},
41+
RunE: func(cmd *cobra.Command, args []string) error {
42+
srv, err := grpc.NewServer(cmd.Context(), &opts)
43+
if err != nil {
44+
return err
45+
}
46+
grpcServer, err := srv.ListenAndServe()
47+
stopCh := signals.SetupSignalHandler()
48+
serverShutdownTimeout := time.Duration(time.Second * 30)
49+
sd, _ := signals.NewShutdown(serverShutdownTimeout, cmd.Context())
50+
sd.Graceful(stopCh, grpcServer, cmd.Context())
51+
return err
52+
},
53+
}
54+
f := cmd.Flags()
55+
f.Int64VarP(&opts.Port, "port", "p", 3001, "Port to run the server on")
56+
f.StringVarP(&opts.ServiceName, "service-name", "s", "api-server", "Server service name")
57+
return cmd
58+
}

docker-bake.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"group": {
3+
"default": {
4+
"targets": [
5+
"server"
6+
]
7+
}
8+
},
9+
"target": {
10+
"server": {
11+
"platforms": [
12+
"linux/amd64",
13+
"linux/arm64"
14+
],
15+
"dockerfile": "build/images/server/Dockerfile",
16+
"context": "./"
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)