-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new plugin for copying static files (#132)
- Loading branch information
Showing
66 changed files
with
325 additions
and
13 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ environment: | |
name: helm-installation | ||
- proto: ytt-render-test | ||
name: ytt-installation | ||
- proto: static-test |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
examples/integration-tests/prototypes/static-test/static/literal.yaml
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,9 @@ | ||
--- | ||
# https://kubernetes.io/docs/concepts/configuration/configmap/ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: static-test-cm | ||
namespace: default | ||
data: | ||
key: value |
File renamed without changes.
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,19 @@ | ||
# Integration tests | ||
|
||
This directory contains configuration for myks' integration tests. | ||
|
||
## Test areas | ||
|
||
### Inheritance | ||
|
||
This examples tests the full power of myks inheritance for helm and ytt rendering leveraging: | ||
|
||
- config from the base app | ||
- config from environment group level | ||
- config from application level | ||
|
||
Both environment group level and application level are rendering with prototype override config as well as application specific config. | ||
|
||
### Static files | ||
|
||
This example tests the ability to correctly render static files from the `static` directories. |
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ spec: | |
name: mykso-dev | ||
namespace: helm-installation | ||
source: | ||
path: examples/inheritance-test/rendered/envs/mykso-dev/helm-installation | ||
path: examples/integration-tests/rendered/envs/mykso-dev/helm-installation | ||
plugin: | ||
name: argocd-vault-plugin-v1.0.0 | ||
repoURL: [email protected]:mykso/myks.git | ||
|
25 changes: 25 additions & 0 deletions
25
examples/integration-tests/rendered/argocd/mykso-dev/app-static-test.yaml
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,25 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
metadata: | ||
name: app-mykso-dev-static-test | ||
namespace: system-argocd | ||
finalizers: | ||
- resources-finalizer.argocd.argoproj.io | ||
spec: | ||
project: env-mykso-dev | ||
destination: | ||
name: mykso-dev | ||
namespace: static-test | ||
source: | ||
path: examples/integration-tests/rendered/envs/mykso-dev/static-test | ||
plugin: | ||
name: argocd-vault-plugin-v1.0.0 | ||
repoURL: [email protected]:mykso/myks.git | ||
targetRevision: main | ||
syncPolicy: | ||
automated: | ||
prune: true | ||
selfHeal: true | ||
syncOptions: | ||
- CreateNamespace=true | ||
- ServerSideApply=true |
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ spec: | |
name: mykso-dev | ||
namespace: ytt-installation | ||
source: | ||
path: examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation | ||
path: examples/integration-tests/rendered/envs/mykso-dev/ytt-installation | ||
plugin: | ||
name: argocd-vault-plugin-v1.0.0 | ||
repoURL: [email protected]:mykso/myks.git | ||
|
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
examples/integration-tests/rendered/envs/mykso-dev/static-test/static/literal.yaml
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,9 @@ | ||
--- | ||
# https://kubernetes.io/docs/concepts/configuration/configmap/ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: static-test-cm | ||
namespace: default | ||
data: | ||
key: value |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,46 @@ | ||
package myks | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
const StaticFilesStepName = "static-files" | ||
|
||
func (a *Application) copyStaticFiles() (err error) { | ||
logStaticFiles := func(files []string) { | ||
log.Trace().Strs("staticFiles", files).Msg(a.Msg(StaticFilesStepName, "Static files")) | ||
} | ||
staticFilesDirs := []string{} | ||
|
||
// 1. Static files from the prototype | ||
prototypeStaticFilesDir := filepath.Join(a.Prototype, a.e.g.StaticFilesDirName) | ||
if ok, err := isExist(prototypeStaticFilesDir); err != nil { | ||
return err | ||
} else if ok { | ||
staticFilesDirs = append(staticFilesDirs, prototypeStaticFilesDir) | ||
} | ||
logStaticFiles(staticFilesDirs) | ||
// 2. Static files from prototype overrides | ||
staticFilesDirs = append(staticFilesDirs, a.e.collectBySubpath(filepath.Join("_proto", a.prototypeDirName(), a.e.g.StaticFilesDirName))...) | ||
logStaticFiles(staticFilesDirs) | ||
|
||
// 3. Static files from the environment | ||
staticFilesDirs = append(staticFilesDirs, a.e.collectBySubpath(filepath.Join("_env", a.e.g.StaticFilesDirName))...) | ||
logStaticFiles(staticFilesDirs) | ||
// 4. Static files from the application | ||
staticFilesDirs = append(staticFilesDirs, a.e.collectBySubpath(filepath.Join("_apps", a.Name, a.e.g.StaticFilesDirName))...) | ||
logStaticFiles(staticFilesDirs) | ||
|
||
staticFilesDestination := filepath.Join(a.getDestinationDir(), a.e.g.StaticFilesDirName) | ||
|
||
for _, staticFilesDir := range staticFilesDirs { | ||
if err = copyDir(staticFilesDir, staticFilesDestination, true); err != nil { | ||
log.Error().Err(err).Msg(a.Msg(StaticFilesStepName, "Unable to copy static files")) | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
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,95 @@ | ||
package myks | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/creasty/defaults" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func TestApplication_copyStaticFiles(t *testing.T) { | ||
defer chdir(t, "../../testData/static-test")() | ||
|
||
envName := "static-test-env" | ||
appName := "static-test-app" | ||
protoName := "static-test-proto" | ||
|
||
globe := &Globe{} | ||
if err := defaults.Set(globe); err != nil { | ||
log.Fatal().Err(err).Msg("Unable to set defaults") | ||
} | ||
|
||
env := &Environment{ | ||
Id: envName, | ||
g: globe, | ||
Dir: filepath.Join(globe.EnvironmentBaseDir, envName), | ||
} | ||
|
||
app := &Application{ | ||
Name: appName, | ||
Prototype: fmt.Sprintf("%s/%s", globe.PrototypesDir, protoName), | ||
e: env, | ||
} | ||
|
||
targetDir := app.getDestinationDir() | ||
|
||
isIgnored := func(info os.DirEntry) bool { | ||
return info.IsDir() || info.Name() == ".keep" || info.Name() == ".gitignore" | ||
} | ||
|
||
// Cleanup copied files | ||
defer func() { | ||
if err := filepath.WalkDir(targetDir, func(path string, info os.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if isIgnored(info) { | ||
return nil | ||
} | ||
return os.Remove(path) | ||
}); err != nil { | ||
t.Errorf("copyStaticFiles() error = %v", err) | ||
} | ||
}() | ||
|
||
if err := app.copyStaticFiles(); err != nil { | ||
t.Errorf("copyStaticFiles() error = %v", err) | ||
} | ||
|
||
expectedFiles := map[string]string{ | ||
"/static/app.txt": "", | ||
"/static/app_override.txt": "", | ||
"/static/conflict.txt": "application", | ||
"/static/env.txt": "", | ||
"/static/env_override.txt": "", | ||
"/static/proto.txt": "", | ||
"/static/proto_override.txt": "", | ||
} | ||
|
||
generatedFiles := map[string]string{} | ||
if err := filepath.WalkDir(targetDir, func(path string, info os.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if isIgnored(info) { | ||
return nil | ||
} | ||
|
||
content, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
path = strings.TrimPrefix(path, targetDir) | ||
generatedFiles[path] = strings.Trim(string(content), "\n") | ||
|
||
return nil | ||
}); err != nil { | ||
t.Errorf("copyStaticFiles() error = %v", err) | ||
} | ||
|
||
assertEqual(t, generatedFiles, expectedFiles) | ||
} |
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
Oops, something went wrong.