Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#4157 #4161 (#4163)

* Templating commit message used by Event watcher (#4120)

* Added ability to teplate eventWatcher.gitRepos.commitMessage

* parse template in the eventWatcher handler side

* Parse template in the eventWatcher handler side

* Fix html/template to text/template

* There was a useless process when retrieving rules, so I omitted it.

* Delete html/template

* Update pkg/app/piped/eventwatcher/eventwatcher.go

Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>

* Update pkg/app/piped/eventwatcher/eventwatcher.go

Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>

* Using template variables are only Value and EventName.

* Update pkg/app/piped/eventwatcher/eventwatcher.go

Co-authored-by: knanao <nao.7ken@gmail.com>

* Update pkg/app/piped/eventwatcher/eventwatcher.go

Co-authored-by: knanao <nao.7ken@gmail.com>

* Fix syntax error

* Update pkg/app/piped/eventwatcher/eventwatcher.go

Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>

Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>
Co-authored-by: knanao <nao.7ken@gmail.com>

* Add environment variable expire web session (#4127)

* add field session-ttl to project

* edit values

* reflect ttl config to session

* return values

* add field in document

* return config

* change variable name

* modify document and manifest

* modify docs

* change minites tp hours

* regen

* Change build tag every time when make run/pipecd (#4130)

* add unix time to tail of build tag

* modify assigning

* change variable name

* change type pf assign

* Fix docs wrong params name (#4132)

* Fix pod config for envoy upstreaming termination error (#4134)

* add lifecycle

* add preStop to api server's manifest

* return makefile

* Fix Fix parseComitMsg's comment (#4135)

* Add kubectl version to stage log (#4137)

* Add kubectl version to stage log

* Update pkg/app/piped/executor/kubernetes/kubernetes.go

Co-authored-by: knanao <nao.7ken@gmail.com>

Co-authored-by: knanao <nao.7ken@gmail.com>

* Add pipecd builtin tags to ECS resources (#4140)

* Add tags to aws resources.

* Small fix

* Small fix

* Fix initial slice length.

* Add TagResource function

* Fix deploy process

* Add tags to aws resources.

* Small fix

* Small fix

* Fix initial slice length.

* Add TagResource function

* Fix deploy process

* Delete Unnecessary blank lines

* Change how to add task's tags

* Delete TagResource method

* Fix based on linter

* Apply review

* add builtin-labels

* Add tagResource func

* Set default value of PropagateTags

* Apply review

* Apply review

* Add upgrade a release method for helm (#4143)

* tool: Replace set-output with GITHUB_OUTPUT (#4155)

* Make all changes that not be listed in ignores but placed under appDir considered as touched commit (#4157)

* Release v0.41.4 (#4161)

* Release v0.41.4

* Update the release note

---------

Co-authored-by: funera1 <60760935+funera1@users.noreply.github.com>
Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>
Co-authored-by: kevin55156 <68955641+kevin55156@users.noreply.github.com>
Co-authored-by: Tomoki Hori <50762864+TonkyH@users.noreply.github.com>
Co-authored-by: Naoki Kanatani <k12naoki@gmail.com>
  • Loading branch information
6 people committed Feb 7, 2023
1 parent a7c563c commit 1d3ef27
Show file tree
Hide file tree
Showing 29 changed files with 481 additions and 138 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ test/integration:
# Run commands

.PHONY: run/pipecd
run/pipecd: BUILD_VERSION ?= $(shell git describe --tags --always --dirty --abbrev=7)
run/pipecd: $(eval TIMESTAMP = $(shell date +%s))
run/pipecd: BUILD_VERSION ?= "$(shell git describe --tags --always --abbrev=7)-$(TIMESTAMP)"
run/pipecd: BUILD_COMMIT ?= $(shell git rev-parse HEAD)
run/pipecd: BUILD_DATE ?= $(shell date -u '+%Y%m%d-%H%M%S')
run/pipecd: BUILD_LDFLAGS_PREFIX := -X github.com/pipe-cd/pipecd/pkg/version
Expand Down
2 changes: 1 addition & 1 deletion RELEASE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: v0.41.2
tag: v0.41.4

releaseNoteGenerator:
showCommitter: false
Expand Down
26 changes: 26 additions & 0 deletions docs/content/en/blog/releases/v0.41.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: "Release v0.41.4"
linkTitle: "Release v0.41.4"
date: 2023-02-07
description: >
Release v0.41.4
---

## Changes since v0.41.3

### New Features
* Templating commit message used by Event watcher ([#4120](https://github.com/pipe-cd/pipecd/pull/4120))
* Add environment variable expire web session ([#4127](https://github.com/pipe-cd/pipecd/pull/4127))

### Notable Changes
* Make all changes that not be listed in ignores but placed under appDir considered as touched commit ([#4157](https://github.com/pipe-cd/pipecd/pull/4157))

### Internal Changes
* tool: Replace set-output with GITHUB_OUTPUT ([#4155](https://github.com/pipe-cd/pipecd/pull/4155))
* Add pipecd builtin tags to ECS resources ([#4140](https://github.com/pipe-cd/pipecd/pull/4140))
* Add upgrade a release method for helm ([#4143](https://github.com/pipe-cd/pipecd/pull/4143))
* Add kubectl version to stage log ([#4137](https://github.com/pipe-cd/pipecd/pull/4137))
* Fix pod config for envoy upstreaming termination error ([#4134](https://github.com/pipe-cd/pipecd/pull/4134))
* Change build tag every time when make run/pipecd ([#4130](https://github.com/pipe-cd/pipecd/pull/4130))
* Fix parseCommitMsg's comment ([#4135](https://github.com/pipe-cd/pipecd/pull/4135))
* Fix docs wrong params name ([#4132](https://github.com/pipe-cd/pipecd/pull/4132))
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Note: You can get examples for those object from [here](../../examples/#ecs-appl
| Field | Type | Description | Required |
|-|-|-|-|
| name | string | The template name to refer. | Yes |
| args | map[string]string | The arguments for custom-args. | No |
| appArgs | map[string]string | The arguments for custom-args. | No |

## StageOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Must be one of the following objects:
|-|-|-|-|
| name | string | The unique name of the configuration. | Yes |
| provider | string | The SSO service provider. Can be one of the following values<br>`GITHUB`, `GOOGLE`... | Yes |
| sessionTtl | int | The time to live of session for SSO login. Unit is `hour`. Default is 7 * 24 hours. | No |
| github | [SSOConfigGitHub](#ssoconfiggithub) | GitHub sso configuration. | No |
| google | [SSOConfigGoogle](#ssoconfiggoogle) | Google sso configuration. | No |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ Note: You can get examples for those object from [here](../../examples/#ecs-appl
| Field | Type | Description | Required |
|-|-|-|-|
| name | string | The template name to refer. | Yes |
| args | map[string]string | The arguments for custom-args. | No |
| appArgs | map[string]string | The arguments for custom-args. | No |

## StageOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ Note: You can get examples for those object from [here](../../examples/#ecs-appl
| Field | Type | Description | Required |
|-|-|-|-|
| name | string | The template name to refer. | Yes |
| args | map[string]string | The arguments for custom-args. | No |
| appArgs | map[string]string | The arguments for custom-args. | No |

## StageOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ Note: You can get examples for those object from [here](../../examples/#ecs-appl
| Field | Type | Description | Required |
|-|-|-|-|
| name | string | The template name to refer. | Yes |
| args | map[string]string | The arguments for custom-args. | No |
| appArgs | map[string]string | The arguments for custom-args. | No |

## StageOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ Note: You can get examples for those object from [here](../../examples/#ecs-appl
| Field | Type | Description | Required |
|-|-|-|-|
| name | string | The template name to refer. | Yes |
| args | map[string]string | The arguments for custom-args. | No |
| appArgs | map[string]string | The arguments for custom-args. | No |

## StageOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Note: You can get examples for those object from [here](../../examples/#ecs-appl
| Field | Type | Description | Required |
|-|-|-|-|
| name | string | The template name to refer. | Yes |
| args | map[string]string | The arguments for custom-args. | No |
| appArgs | map[string]string | The arguments for custom-args. | No |

## StageOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Must be one of the following objects:
|-|-|-|-|
| name | string | The unique name of the configuration. | Yes |
| provider | string | The SSO service provider. Can be one of the following values<br>`GITHUB`, `GOOGLE`... | Yes |
| sessionTtl | int | The time to live of session for SSO login. Unit is `hour`. Default is 7 * 24 hours. | No |
| github | [SSOConfigGitHub](#ssoconfiggithub) | GitHub sso configuration. | No |
| google | [SSOConfigGoogle](#ssoconfiggoogle) | Google sso configuration. | No |

Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/docs/user-guide/configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Note: You can get examples for those object from [here](../../examples/#ecs-appl
| Field | Type | Description | Required |
|-|-|-|-|
| name | string | The template name to refer. | Yes |
| args | map[string]string | The arguments for custom-args. | No |
| appArgs | map[string]string | The arguments for custom-args. | No |

## StageOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Must be one of the following objects:
|-|-|-|-|
| name | string | The unique name of the configuration. | Yes |
| provider | string | The SSO service provider. Can be one of the following values<br>`GITHUB`, `GOOGLE`... | Yes |
| sessionTtl | int | The time to live of session for SSO login. Unit is `hour`. Default is 7 * 24 hours. | No |
| github | [SSOConfigGitHub](#ssoconfiggithub) | GitHub sso configuration. | No |
| google | [SSOConfigGoogle](#ssoconfiggoogle) | Google sso configuration. | No |

Expand Down
4 changes: 4 additions & 0 deletions manifests/pipecd/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ spec:
- name: pipecd-config
mountPath: /etc/pipecd-config
readOnly: true
lifecycle:
preStop:
exec:
command: [ "/bin/sh", "-c", "sleep 30" ]
{{- if .Values.server.resources }}
resources:
{{- toYaml .Values.server.resources | nindent 12 }}
Expand Down
34 changes: 32 additions & 2 deletions pkg/app/piped/eventwatcher/eventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"path/filepath"
"regexp/syntax"
"strconv"
"strings"
"sync"
"text/template"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -149,6 +151,7 @@ func (w *watcher) run(ctx context.Context, repo git.Repo, repoCfg config.PipedRe
commitMsg string
includedCfgs, excludedCfgs []string
)

// Use user-defined settings if there is.
for _, r := range w.config.EventWatcher.GitRepos {
if r.RepoID != repoCfg.RepoID {
Expand Down Expand Up @@ -631,9 +634,11 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit
return nil
}

if commitMsg == "" {
commitMsg = fmt.Sprintf(defaultCommitMessageFormat, latestData, eventName)
args := argsTemplate{
Value: latestData,
EventName: eventName,
}
commitMsg = parseCommitMsg(commitMsg, args)
if err := repo.CommitChanges(ctx, repo.GetClonedBranch(), commitMsg, false, changes); err != nil {
return fmt.Errorf("failed to perform git commit: %w", err)
}
Expand Down Expand Up @@ -747,3 +752,28 @@ func modifyText(path, regexText, newValue string) ([]byte, bool, error) {

return newText, false, nil
}

// argsTemplate represents a collection of available template arguments.
type argsTemplate struct {
Value string
EventName string
}

// parseCommitMsg parses event watcher's commit message.
// Currently, only {{ .Value }} and {{ .EventName }} are supported.
func parseCommitMsg(msg string, args argsTemplate) string {
if msg == "" {
return fmt.Sprintf(defaultCommitMessageFormat, args.Value, args.EventName)
}

t, err := template.New("EventWatcherCommitMsgTemplate").Parse(msg)
if err != nil {
return msg
}

buf := new(strings.Builder)
if err := t.Execute(buf, args); err != nil {
return msg
}
return buf.String()
}
21 changes: 21 additions & 0 deletions pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ func loadServiceDefinition(in *executor.Input, serviceDefinitionFile string, ds
return types.Service{}, false
}

serviceDefinition.Tags = append(
serviceDefinition.Tags,
provider.MakeTags(map[string]string{
provider.LabelManagedBy: provider.ManagedByPiped,
provider.LabelPiped: in.PipedConfig.PipedID,
provider.LabelApplication: in.Deployment.ApplicationId,
provider.LabelCommitHash: in.Deployment.CommitHash(),
})...,
)

in.LogPersister.Infof("Successfully loaded the ECS service definition at commit %s", ds.Revision)
return serviceDefinition, true
}
Expand Down Expand Up @@ -147,6 +157,10 @@ func applyServiceDefinition(ctx context.Context, cli provider.Client, serviceDef
if err != nil {
return nil, fmt.Errorf("failed to update ECS service %s: %v", *serviceDefinition.ServiceName, err)
}
if err := cli.TagResource(ctx, *service.ServiceArn, serviceDefinition.Tags); err != nil {
return nil, fmt.Errorf("failed to update tags of ECS service %s: %v", *serviceDefinition.ServiceName, err)
}

} else {
service, err = cli.CreateService(ctx, serviceDefinition)
if err != nil {
Expand All @@ -172,6 +186,12 @@ func runStandaloneTask(
}

in.LogPersister.Infof("Start applying the ECS task definition")
tags := provider.MakeTags(map[string]string{
provider.LabelManagedBy: provider.ManagedByPiped,
provider.LabelPiped: in.PipedConfig.PipedID,
provider.LabelApplication: in.Deployment.ApplicationId,
provider.LabelCommitHash: in.Deployment.CommitHash(),
})
td, err := applyTaskDefinition(ctx, client, taskDefinition)
if err != nil {
in.LogPersister.Errorf("Failed to apply ECS task definition: %v", err)
Expand All @@ -184,6 +204,7 @@ func runStandaloneTask(
ecsInput.ClusterArn,
ecsInput.LaunchType,
&ecsInput.AwsVpcConfiguration,
tags,
)
if err != nil {
in.LogPersister.Errorf("Failed to run ECS task: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/piped/executor/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (e *deployExecutor) Execute(sig executor.StopSignal) model.StageStatus {
}
}

if e.appCfg.Input.KubectlVersion != "" {
e.LogPersister.Infof("kubectl version %s will be used.", e.appCfg.Input.KubectlVersion)
}

e.applierGetter, err = newApplierGroup(e.Deployment.PlatformProvider, *e.appCfg, e.PipedConfig, e.Logger)
if err != nil {
e.LogPersister.Error(err.Error())
Expand Down
18 changes: 15 additions & 3 deletions pkg/app/piped/platformprovider/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ func (c *client) CreateService(ctx context.Context, service types.Service) (*typ
PlacementConstraints: service.PlacementConstraints,
PlacementStrategy: service.PlacementStrategy,
PlatformVersion: service.PlatformVersion,
PropagateTags: service.PropagateTags,
PropagateTags: types.PropagateTagsService,
Role: service.RoleArn,
SchedulingStrategy: service.SchedulingStrategy,
ServiceRegistries: service.ServiceRegistries,
Tags: service.Tags,
}

output, err := c.ecsClient.CreateService(ctx, input)
if err != nil {
return nil, fmt.Errorf("failed to create ECS service %s: %w", *service.ServiceName, err)
Expand Down Expand Up @@ -151,7 +150,7 @@ func (c *client) RegisterTaskDefinition(ctx context.Context, taskDefinition type
return output.TaskDefinition, nil
}

func (c *client) RunTask(ctx context.Context, taskDefinition types.TaskDefinition, clusterArn string, launchType string, awsVpcConfiguration *appconfig.ECSVpcConfiguration) error {
func (c *client) RunTask(ctx context.Context, taskDefinition types.TaskDefinition, clusterArn string, launchType string, awsVpcConfiguration *appconfig.ECSVpcConfiguration, tags []types.Tag) error {
if taskDefinition.TaskDefinitionArn == nil {
return fmt.Errorf("failed to run task of task family %s: no task definition provided", *taskDefinition.Family)
}
Expand All @@ -160,6 +159,7 @@ func (c *client) RunTask(ctx context.Context, taskDefinition types.TaskDefinitio
TaskDefinition: taskDefinition.Family,
Cluster: aws.String(clusterArn),
LaunchType: types.LaunchType(launchType),
Tags: tags,
}

if len(awsVpcConfiguration.Subnets) > 0 {
Expand Down Expand Up @@ -341,3 +341,15 @@ func (c *client) ModifyListener(ctx context.Context, listenerArn string, routing
_, err := c.elbClient.ModifyListener(ctx, input)
return err
}

func (c *client) TagResource(ctx context.Context, resourceArn string, tags []types.Tag) error {
input := &ecs.TagResourceInput{
ResourceArn: aws.String(resourceArn),
Tags: tags,
}
_, err := c.ecsClient.TagResource(ctx, input)
if err != nil {
return fmt.Errorf("failed to update tag of resource %s: %w", resourceArn, err)
}
return nil
}
20 changes: 19 additions & 1 deletion pkg/app/piped/platformprovider/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ import (
"path/filepath"
"sync"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"go.uber.org/zap"
"golang.org/x/sync/singleflight"

"github.com/pipe-cd/pipecd/pkg/config"
)

const (
LabelManagedBy string = "pipecd-dev-managed-by" // Always be piped.
LabelPiped string = "pipecd-dev-piped" // The id of piped handling this application.
LabelApplication string = "pipecd-dev-application" // The application this resource belongs to.
LabelCommitHash string = "pipecd-dev-commit-hash" // Hash value of the deployed commit.
ManagedByPiped string = "piped"
)

// Client is wrapper of ECS client.
type Client interface {
ECS
Expand All @@ -37,11 +46,12 @@ type ECS interface {
CreateService(ctx context.Context, service types.Service) (*types.Service, error)
UpdateService(ctx context.Context, service types.Service) (*types.Service, error)
RegisterTaskDefinition(ctx context.Context, taskDefinition types.TaskDefinition) (*types.TaskDefinition, error)
RunTask(ctx context.Context, taskDefinition types.TaskDefinition, clusterArn string, launchType string, awsVpcConfiguration *config.ECSVpcConfiguration) error
RunTask(ctx context.Context, taskDefinition types.TaskDefinition, clusterArn string, launchType string, awsVpcConfiguration *config.ECSVpcConfiguration, tags []types.Tag) error
GetPrimaryTaskSet(ctx context.Context, service types.Service) (*types.TaskSet, error)
CreateTaskSet(ctx context.Context, service types.Service, taskDefinition types.TaskDefinition, targetGroup *types.LoadBalancer, scale int) (*types.TaskSet, error)
DeleteTaskSet(ctx context.Context, service types.Service, taskSetArn string) error
UpdateServicePrimaryTaskSet(ctx context.Context, service types.Service, taskSet types.TaskSet) (*types.TaskSet, error)
TagResource(ctx context.Context, resourceArn string, tags []types.Tag) error
}

type ELB interface {
Expand Down Expand Up @@ -109,3 +119,11 @@ var defaultRegistry = &registry{
func DefaultRegistry() Registry {
return defaultRegistry
}

func MakeTags(tags map[string]string) []types.Tag {
resourceTags := make([]types.Tag, 0, len(tags))
for key, value := range tags {
resourceTags = append(resourceTags, types.Tag{Key: aws.String(key), Value: aws.String(value)})
}
return resourceTags
}

0 comments on commit 1d3ef27

Please sign in to comment.