Skip to content

Commit

Permalink
Merge pull request #219 from buildtool/deploy-empty-file
Browse files Browse the repository at this point in the history
fix: ignore empty files during deploy
  • Loading branch information
argoyle authored Apr 25, 2022
2 parents ab66a87 + 535c531 commit 8bcdb01
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func processFile(file *os.File, commit, timestamp, image string, client kubectl.
return err
} else {
content := string(bytes)
if len(strings.TrimSpace(content)) == 0 {
log.Debugf("ignoring empty file '<yellow>%s</yellow>'\n", filepath.Base(file.Name()))
return nil
}
r := strings.NewReplacer("${COMMIT}", commit, "${TIMESTAMP}", timestamp, "${IMAGE}", image)
kubeContent := r.Replace(content)
log.Debugf("trying to apply: \n---\n%s\n---\n", kubeContent)
Expand Down
37 changes: 37 additions & 0 deletions pkg/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,43 @@ func TestDeploy_EnvSpecificFiles(t *testing.T) {
})
}

func TestDeploy_IgnoreEmptyFiles(t *testing.T) {
client := &kubectl.MockKubectl{
Responses: []error{nil},
}

name, _ := ioutil.TempDir(os.TempDir(), "build-tools")
defer func() { _ = os.RemoveAll(name) }()
_ = os.MkdirAll(filepath.Join(name, "k8s", "prod"), 0777)
deployFile := filepath.Join(name, "k8s", "ns-dummy.yaml")
_ = ioutil.WriteFile(deployFile, []byte("dummy yaml content"), 0777)
_ = ioutil.WriteFile(filepath.Join(name, "k8s", "ns-prod.yaml"), []byte(""), 0777)
_ = ioutil.WriteFile(filepath.Join(name, "k8s", "other-dummy.sh"), []byte("dummy script content"), 0777)

logMock := mocks.New()
log.SetHandler(logMock)
log.SetLevel(log.DebugLevel)
err := Deploy(name, "image", "registryUrl", "20190513-17:22:36", client, Args{
Globals: args.Globals{},
Target: "prod",
Context: "",
Namespace: "",
Tag: "abc123",
Timeout: "2m",
})
assert.NoError(t, err)
assert.Equal(t, 0, len(client.Inputs))
logMock.Check(t, []string{
"debug: considering file '<yellow>ns-dummy.yaml</yellow>' for target: <green>prod</green>\n",
"debug: not using file '<red>ns-dummy.yaml</red>' for target: <green>prod</green>\n",
"debug: considering file '<yellow>ns-prod.yaml</yellow>' for target: <green>prod</green>\n",
"debug: using file '<green>ns-prod.yaml</green>' for target: <green>prod</green>\n",
"debug: considering script '<yellow>other-dummy.sh</yellow>' for target: <green>prod</green>\n",
"debug: not using script '<red>other-dummy.sh</red>' for target: <green>prod</green>\n",
"debug: ignoring empty file '<yellow>ns-prod.yaml</yellow>'\n",
})
}

func TestDeploy_ScriptExecution_NameSuffix(t *testing.T) {
client := &kubectl.MockKubectl{
Responses: []error{nil},
Expand Down
2 changes: 1 addition & 1 deletion www/docs/ci/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Read more about available [commands](/commands/build):
[Github Actions]: https://github.com/features/actions
[setup-buildtools-action]: https://github.com/buildtool/setup-buildtools-action
[syntax]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#About-yaml-syntax-for-workflows
[syntax]: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#About-yaml-syntax-for-workflows
2 changes: 1 addition & 1 deletion www/docs/config/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The following registries are supported:
| :------------- | :--------------------- |
| [`dockerhub`](#dockerhub) | [Docker hub](https://hub.docker.com/) |
| [`ecr`](#ecr) | [AWS Elastic Container Registry](https://docs.aws.amazon.com/ecr/index.html) |
| [`github`](#github) | [Github package registry](https://help.github.com/en/github/managing-packages-with-github-package-registry/about-github-package-registry) |
| [`github`](#github) | [Github package registry](https://docs.github.com/en/packages/learn-github-packages/introduction-to-github-packages) |
| [`gitlab`](#gitlab) | [Gitlab container registry](https://docs.gitlab.com/ee/user/packages/container_registry/) |
| [`quay`](#quay) | [Quay docker registry](https://docs.quay.io/) |
| [`gcr`](#gcr) | [Google Container registry](https://cloud.google.com/container-registry) |
Expand Down
3 changes: 2 additions & 1 deletion www/htmltest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ IgnoreAltMissing: true
HTTPHeaders:
"Range": "bytes=0-10"
"Accept": "*/*"
"User-Agent": "chrome"
"User-Agent": "chrome"
"Accept-Encoding": "gzip"

0 comments on commit 8bcdb01

Please sign in to comment.