Skip to content
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

feat(web): specify pipeline target branch #1023

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
beabb81
refactor: container configurations
m8vago Nov 6, 2024
839cc1f
fix: secret handling
m8vago Nov 25, 2024
76bc1de
fix: build
m8vago Nov 25, 2024
2a6dc53
refactor: remove unused ws messages
m8vago Nov 26, 2024
be6c022
fix: migration
m8vago Nov 27, 2024
b0c93cb
feat(web): api & ui
robot9706 Nov 27, 2024
95e13d6
fix: migration
m8vago Nov 27, 2024
54e16d0
fix: trying to fix config-bundle related tests
m8vago Nov 28, 2024
a6fe6d5
Merge branch 'develop' into feat/deployments-paginated
robot9706 Nov 28, 2024
4badf49
fix: lint
robot9706 Nov 28, 2024
63a2cb9
Merge branch 'feat/deployments-paginated' into refactor/configurations
robot9706 Nov 28, 2024
20ff448
fix: merge
robot9706 Nov 28, 2024
8a28439
feat: deploy list by configbundle
robot9706 Nov 28, 2024
66bfe63
feat: config bundle deployment list
robot9706 Nov 28, 2024
2a20744
feat: use pagination
robot9706 Nov 29, 2024
322ba35
Merge branch 'develop' into refactor/configurations
robot9706 Nov 29, 2024
9c6f837
fix: lint
robot9706 Nov 29, 2024
c2b38c9
fix: update test
robot9706 Nov 29, 2024
4bf2c8f
fix: go lint
robot9706 Dec 2, 2024
c5f654f
fix: deploy bug & separate config schema
robot9706 Dec 2, 2024
a2482b8
Revert "fix: deploy bug & separate config schema"
m8vago Dec 3, 2024
a780d10
fix: deployment null secrets
m8vago Dec 3, 2024
e214b33
feat(web): specify pipeline target branch
robot9706 Dec 3, 2024
677d17b
fix: lint
robot9706 Dec 3, 2024
a942ad0
fix: config bundle e2e
m8vago Dec 3, 2024
0b37410
fix: golang unit tests
m8vago Dec 3, 2024
04f27d3
fix(web): branch default value
robot9706 Dec 3, 2024
885cbd1
fix: setting prefix and container name
m8vago Dec 3, 2024
293a2e2
Merge branch 'develop' into refactor/configurations
m8vago Dec 3, 2024
353b164
fix: duplicated images
m8vago Dec 3, 2024
038495d
fix: container name defaults
m8vago Dec 3, 2024
8b21704
fix: storage saving
m8vago Dec 4, 2024
f42e87f
build: disable e2e
m8vago Dec 4, 2024
44d73ca
fix: remove e2e need
m8vago Dec 4, 2024
e6b8580
fix: lint
m8vago Dec 4, 2024
37755f0
Merge branch 'refactor/configurations' into feat/release-candidate
m8vago Dec 4, 2024
3d3afac
fix: go_push needs
m8vago Dec 4, 2024
e0bba87
Merge branch 'feat/release-candidate' into feat/pipeline-target-branch
robot9706 Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy_external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflows:
- 'product_builder'
branches:
- 'develop'
- 'feat/release-candidate'
types:
- completed
permissions:
Expand Down
36 changes: 16 additions & 20 deletions .github/workflows/product_builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ jobs:
crux: ${{ steps.filter.outputs.crux }}
cruxui: ${{ steps.filter.outputs.cruxui }}
kratos: ${{ steps.filter.outputs.kratos }}
tag: ${{ steps.settag.outputs.tag }}
tag: "0.15.0-rc" # ${{ steps.settag.outputs.tag }}
extratag: ${{ steps.settag.outputs.extratag }}
version: ${{ steps.settag.outputs.version }}
version: "0.15.0-rc" # ${{ steps.settag.outputs.version }}
minorversion: ${{ steps.settag.outputs.minorversion }}
release: ${{ steps.release.outputs.release }}
steps:
Expand Down Expand Up @@ -669,11 +669,10 @@ jobs:
defaults:
run:
working-directory: ${{ env.GOLANG_WORKING_DIRECTORY }}
needs: [gather_changes, e2e]
needs: [gather_changes, go_build]
if: |
always() &&
(github.ref_name == 'develop' || github.ref_name == 'main' || github.ref_type == 'tag') &&
needs.e2e.result == 'success' &&
needs.go_build.result == 'success' &&
(needs.crux_build.result == 'success' || needs.crux_build.result == 'skipped') &&
(needs.crux-ui_build.result == 'success' || needs.crux-ui_build.result == 'skipped') &&
Expand Down Expand Up @@ -735,16 +734,16 @@ jobs:
container:
image: ghcr.io/dyrector-io/dyrectorio/builder-images/signer:2
needs: [gather_changes, go_push]
if: |
always() &&
(github.ref_name == 'develop' || github.ref_name == 'main' || github.ref_type == 'tag') &&
needs.e2e.result == 'success' &&
needs.go_build.result == 'success' &&
(needs.crux_build.result == 'success' || needs.crux_build.result == 'skipped') &&
(needs.crux-ui_build.result == 'success' || needs.crux-ui_build.result == 'skipped') &&
(needs.kratos_build.result == 'success' || needs.kratos_build.result == 'skipped') &&
needs.conventional_commits.result == 'success' &&
needs.gather_changes.result == 'success' && needs.go_push.result == 'success'
# if: |
# always() &&
# (github.ref_name == 'develop' || github.ref_name == 'main' || github.ref_type == 'tag') &&
# needs.e2e.result == 'success' &&
# needs.go_build.result == 'success' &&
# (needs.crux_build.result == 'success' || needs.crux_build.result == 'skipped') &&
# (needs.crux-ui_build.result == 'success' || needs.crux-ui_build.result == 'skipped') &&
# (needs.kratos_build.result == 'success' || needs.kratos_build.result == 'skipped') &&
# needs.conventional_commits.result == 'success' &&
# needs.gather_changes.result == 'success' && needs.go_push.result == 'success'
environment: Workflow - Protected
steps:
- name: Login to GHCR
Expand Down Expand Up @@ -800,11 +799,10 @@ jobs:
runs-on: ubuntu-22.04
container:
image: ghcr.io/dyrector-io/dyrectorio/builder-images/signer:2
needs: [crux_build, e2e, gather_changes]
needs: [crux_build, gather_changes]
if: |
always() &&
(github.ref_name == 'develop' || github.ref_name == 'main' || github.ref_type == 'tag') &&
needs.e2e.result == 'success' &&
(needs.go_build.result == 'success' || needs.go_build.result == 'skipped') &&
needs.crux_build.result == 'success' &&
(needs.crux-ui_build.result == 'success' || needs.crux-ui_build.result == 'skipped') &&
Expand Down Expand Up @@ -863,11 +861,10 @@ jobs:
runs-on: ubuntu-22.04
container:
image: ghcr.io/dyrector-io/dyrectorio/builder-images/signer:2
needs: [crux-ui_build, e2e, gather_changes]
needs: [crux-ui_build, gather_changes]
if: |
always() &&
(github.ref_name == 'develop' || github.ref_name == 'main' || github.ref_type == 'tag') &&
needs.e2e.result == 'success' &&
(needs.go_build.result == 'success' || needs.go_build.result == 'skipped') &&
(needs.crux_build.result == 'success' || needs.crux_build.result == 'skipped') &&
needs.crux-ui_build.result == 'success' &&
Expand Down Expand Up @@ -926,11 +923,10 @@ jobs:
runs-on: ubuntu-22.04
container:
image: ghcr.io/dyrector-io/dyrectorio/builder-images/signer:2
needs: [kratos_build, e2e, gather_changes]
needs: [kratos_build, gather_changes]
if: |
always() &&
(github.ref_name == 'develop' || github.ref_name == 'main' || github.ref_type == 'tag') &&
needs.e2e.result == 'success' &&
(needs.go_build.result == 'success' || needs.go_build.result == 'skipped') &&
(needs.crux_build.result == 'success' || needs.crux_build.result == 'skipped') &&
(needs.crux-ui_build.result == 'success' || needs.crux-ui_build.result == 'skipped') &&
Expand Down
83 changes: 49 additions & 34 deletions golang/internal/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ClientLoop struct {

type (
DeployFunc func(context.Context, *dogger.DeploymentLogger, *v1.DeployImageRequest, *v1.VersionData) error
DeploySharedSecretsFunc func(context.Context, string, map[string]string) error
WatchContainerStatusFunc func(context.Context, string, bool) (*ContainerStatusStream, error)
DeleteFunc func(context.Context, string, string) error
SecretListFunc func(context.Context, string, string) ([]string, error)
Expand All @@ -94,6 +95,7 @@ type (

type WorkerFunctions struct {
Deploy DeployFunc
DeploySharedSecrets DeploySharedSecretsFunc
WatchContainerStatus WatchContainerStatusFunc
Delete DeleteFunc
SecretList SecretListFunc
Expand Down Expand Up @@ -186,7 +188,13 @@ func fetchCertificatesFromURL(ctx context.Context, addr string) (*x509.CertPool,
func (cl *ClientLoop) grpcProcessCommand(command *agent.AgentCommand) {
switch {
case command.GetDeploy() != nil:
go executeVersionDeployRequest(cl.Ctx, command.GetDeploy(), cl.WorkerFuncs.Deploy, cl.AppConfig)
go executeDeployRequest(
cl.Ctx,
command.GetDeploy(),
cl.WorkerFuncs.Deploy,
cl.WorkerFuncs.DeploySharedSecrets,
cl.AppConfig,
)
case command.GetContainerState() != nil:
go executeWatchContainerStatus(cl.Ctx, command.GetContainerState(), cl.WorkerFuncs.WatchContainerStatus)
case command.GetContainerDelete() != nil:
Expand Down Expand Up @@ -455,9 +463,9 @@ func (cl *ClientLoop) handleGrpcTokenError(err error, token *config.ValidJWT) {
}
}

func executeVersionDeployRequest(
ctx context.Context, req *agent.VersionDeployRequest,
deploy DeployFunc, appConfig *config.CommonConfiguration,
func executeDeployRequest(
ctx context.Context, req *agent.DeployRequest,
deploy DeployFunc, deploySecrets DeploySharedSecretsFunc, appConfig *config.CommonConfiguration,
) {
if deploy == nil {
log.Error().Msg("Deploy function not implemented")
Expand Down Expand Up @@ -486,10 +494,27 @@ func executeVersionDeployRequest(
return
}

failed := false
var deployStatus common.DeploymentStatus
deployStatus := common.DeploymentStatus_FAILED
defer func() {
dog.WriteDeploymentStatus(deployStatus)

err = statusStream.CloseSend()
if err != nil {
log.Error().Stack().Err(err).Str("deployment", req.Id).Msg("Status close error")
}
}()

if len(req.Secrets) > 0 {
dog.WriteInfo("Deploying secrets")
err = deploySecrets(ctx, req.Prefix, req.Secrets)
if err != nil {
dog.WriteError(err.Error())
return
}
}

for i := range req.Requests {
imageReq := mapper.MapDeployImage(req.Requests[i], appConfig)
imageReq := mapper.MapDeployImage(req.Prefix, req.Requests[i], appConfig)
dog.SetRequestID(imageReq.RequestID)

var versionData *v1.VersionData
Expand All @@ -498,24 +523,12 @@ func executeVersionDeployRequest(
}

if err = deploy(ctx, dog, imageReq, versionData); err != nil {
failed = true
dog.WriteError(err.Error())
return
}
}

if failed {
deployStatus = common.DeploymentStatus_FAILED
} else {
deployStatus = common.DeploymentStatus_SUCCESSFUL
}

dog.WriteDeploymentStatus(deployStatus)

err = statusStream.CloseSend()
if err != nil {
log.Error().Stack().Err(err).Str("deployment", req.Id).Msg("Status close error")
return
}
deployStatus = common.DeploymentStatus_SUCCESSFUL
}

func streamContainerStatus(
Expand Down Expand Up @@ -636,13 +649,10 @@ func executeDeleteMultipleContainers(
req *common.DeleteContainersRequest,
deleteFn DeleteContainersFunc,
) *AgentGrpcError {
var prefix, name string
if req.GetContainer() != nil {
prefix = req.GetContainer().Prefix
name = req.GetContainer().Name
} else {
prefix = req.GetPrefix()
name = ""
prefix, name, err := mapper.MapContainerOrPrefixToPrefixName(req.Target)
if err != nil {
log.Error().Err(err).Msg("Failed to delete multiple containers")
return agentError(ctx, err)
}

ctx = metadata.AppendToOutgoingContext(ctx, "dyo-container-prefix", prefix, "dyo-container-name", name)
Expand All @@ -653,7 +663,7 @@ func executeDeleteMultipleContainers(

log.Info().Msg("Deleting multiple containers")

err := deleteFn(ctx, req)
err = deleteFn(ctx, req)
if err != nil {
log.Error().Stack().Err(err).Msg("Failed to delete multiple containers")
return agentError(ctx, err)
Expand Down Expand Up @@ -741,8 +751,15 @@ func executeSecretList(
listFunc SecretListFunc,
appConfig *config.CommonConfiguration,
) *AgentGrpcError {
prefix := command.Container.Prefix
name := command.Container.Name
var prefix string
name := ""

if command.Target.GetContainer() != nil {
prefix = command.Target.GetContainer().Prefix
name = command.Target.GetContainer().Name
} else {
prefix = command.Target.GetPrefix()
}

ctx = metadata.AppendToOutgoingContext(ctx, "dyo-container-prefix", prefix, "dyo-container-name", name)

Expand All @@ -765,10 +782,8 @@ func executeSecretList(
}

resp := &common.ListSecretsResponse{
Prefix: prefix,
Name: name,
Target: command.Target,
PublicKey: publicKey,
HasKeys: keys != nil,
Keys: keys,
}

Expand Down
60 changes: 29 additions & 31 deletions golang/internal/mapper/grpc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mapper

import (
"errors"
"fmt"
"strings"
"time"
Expand All @@ -25,33 +26,18 @@ import (
corev1 "k8s.io/api/core/v1"
)

func mapInstanceConfig(in *agent.InstanceConfig) v1.InstanceConfig {
instanceConfig := v1.InstanceConfig{
ContainerPreName: in.Prefix,
Name: in.Prefix,
SharedEnvironment: map[string]string{},
}

if in.RepositoryPrefix != nil {
instanceConfig.RepositoryPreName = *in.RepositoryPrefix
}

if in.MountPath != nil {
instanceConfig.MountPath = *in.MountPath
}
var ErrNoTargetContainerOrPrefix = errors.New("no target container or prefix")

if in.Environment != nil {
instanceConfig.Environment = in.Environment
}

return instanceConfig
}

func MapDeployImage(req *agent.DeployRequest, appConfig *config.CommonConfiguration) *v1.DeployImageRequest {
func MapDeployImage(prefix string, req *agent.DeployWorkloadRequest, appConfig *config.CommonConfiguration) *v1.DeployImageRequest {
res := &v1.DeployImageRequest{
RequestID: req.Id,
InstanceConfig: mapInstanceConfig(req.InstanceConfig),
ContainerConfig: mapContainerConfig(req),
RequestID: req.Id,
InstanceConfig: v1.InstanceConfig{
UseSharedEnvs: false,
Environment: map[string]string{},
SharedEnvironment: map[string]string{},
ContainerPreName: prefix,
},
ContainerConfig: mapContainerConfig(prefix, req),
ImageName: req.ImageName,
Tag: req.Tag,
Registry: req.Registry,
Expand All @@ -68,22 +54,18 @@ func MapDeployImage(req *agent.DeployRequest, appConfig *config.CommonConfigurat

v1.SetDeploymentDefaults(res, appConfig)

if req.RuntimeConfig != nil {
res.RuntimeConfig = v1.Base64JSONBytes(*req.RuntimeConfig)
}

if req.Registry != nil {
res.Registry = req.Registry
}
return res
}

func mapContainerConfig(in *agent.DeployRequest) v1.ContainerConfig {
func mapContainerConfig(prefix string, in *agent.DeployWorkloadRequest) v1.ContainerConfig {
cc := in.Common

containerConfig := v1.ContainerConfig{
Container: cc.Name,
ContainerPreName: in.InstanceConfig.Prefix,
ContainerPreName: prefix,
Ports: MapPorts(cc.Ports),
PortRanges: mapPortRanges(cc.PortRanges),
Volumes: mapVolumes(cc.Volumes),
Expand Down Expand Up @@ -692,3 +674,19 @@ func MapDockerContainerEventToContainerState(event string) common.ContainerState
return common.ContainerState_CONTAINER_STATE_UNSPECIFIED
}
}

func MapContainerOrPrefixToPrefixName(target *common.ContainerOrPrefix) (prefix, name string, err error) {
if target == nil {
return "", "", ErrNoTargetContainerOrPrefix
}

if target.GetContainer() != nil {
return target.GetContainer().GetPrefix(), target.GetContainer().Name, nil
}

if target.GetPrefix() == "" {
return "", "", ErrNoTargetContainerOrPrefix
}

return target.GetPrefix(), "", nil
}
Loading
Loading