Skip to content

Commit f3e8d07

Browse files
committed
simplify variable usage
1 parent 299fdca commit f3e8d07

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ respective files and pass them to the `docker stack deploy` command.
2222

2323
The stack name can be ommited, in that case the current directory name will be used instead.
2424

25-
## Changes
25+
## Changes to codestation/docker-deploy
2626

2727
- Paths to files are resolved correctly even when docker-deploy is called from an other directory. E.g.: `docker-deploy -c /home/user/deployment/app/app.yml app`
2828

29-
- If there is a variable in the filename such as below, the resulting environment variable will be created based on the parent directory + extension of the file.
29+
- If there is a variable in the filename such as below, the resulting environment variable will be created based on the variable.
3030

3131
```yaml
3232
secrets:
3333
secrets.env:
34-
name: ${APP_NAME}.env.${SECRETS_ENV}
34+
name: ${APP_NAME}.env.${APP_NAME_ENV}
3535
file: ../secrets/${APP_NAME}.env
3636
```
3737

main.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,8 @@ func fileHash(filePath string) (string, error) {
5454
func newFileEnvironment(filePath string, filename string) (string, error) {
5555
variableName := filePath
5656
if strings.Contains(filePath, "$") {
57-
fileExt := path.Ext(filePath)
58-
containingDir := path.Base(path.Dir(filePath))
59-
variableName = containingDir + fileExt
60-
6157
variableInFilePath := strings.Split(strings.Split(filePath, "${")[1],"}")[0]
58+
variableName = strings.Replace(filePath, "${" + variableInFilePath + "}", variableInFilePath, 1)
6259
filePath = strings.Replace(filePath, "${" + variableInFilePath + "}", os.Getenv(variableInFilePath), 1)
6360
// log.Printf("replaced " + variableInFilePath + " to " + os.Getenv(variableInFilePath))
6461
}

0 commit comments

Comments
 (0)