Skip to content

Commit 7b923e0

Browse files
authored
Merge pull request #4 from base2Services/develop
v0.1.1 Release
2 parents cb92b6b + c8818ba commit 7b923e0

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ FROM golang:latest as go
22

33
RUN mkdir /build
44

5-
COPY aws-env.go /build
6-
75
WORKDIR /build
86

97
RUN go get -u github.com/aws/aws-sdk-go
108

11-
RUN CGO_ENABLED=0 GOOS=linux go build -v -o awsenv .
9+
Run go get -u github.com/kataras/golog
10+
11+
COPY .git /build/
12+
COPY aws-env.go /build
13+
14+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.version=$(git describe --tags)" -v -o awsenv .
1215

1316

1417
FROM scratch

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ Searches for SSM Parameters in your AWS account based on the variables provided
1111

1212
## Parameters
1313

14+
### Environment Variables
15+
1416
* `SSM_PATH` [Required] - Complete path structure created in SSM Parameter store
1517
* `AWS_REGION` [Required] - Region in which the SSM Parameters are stored
1618
* `DIRECTORY` [Optional] - Directory path of the .env file. Can contain child directories. Default is `/ssm`. *NOTE:* The default cannot be changed if used in a side car configuration.
19+
* `LOG_LEVEL` [Optional] - Levels such as `fatal`, `error`, `warn`, `info`, `debug`, or `disable`. Default is `info`
1720
* `FORMAT` [Optional] - Format of the .env file.
1821
* unset
1922
```bash
@@ -28,6 +31,10 @@ Searches for SSM Parameters in your AWS account based on the variables provided
2831
DB_PASSWORD='SecretPassword'
2932
```
3033

34+
### Command Line
35+
36+
* `-v` [Optional] - Show version and exit 0
37+
3138
## Parameter Hierarchy
3239

3340
Provide the hierachy structure using the `SSM_PATH` environment variable
@@ -81,7 +88,7 @@ test:
8188
* eval the `/ssm/.env` file to export the environment parameters
8289

8390
```Dockerfile
84-
FROM FROM base2/awsenv as awsenv
91+
FROM base2/awsenv as awsenv
8592
8693
FROM debian:jessie
8794

aws-env.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@ import (
66
"github.com/aws/aws-sdk-go/aws"
77
"github.com/aws/aws-sdk-go/aws/session"
88
"github.com/aws/aws-sdk-go/service/ssm"
9+
"github.com/kataras/golog"
910
"io/ioutil"
10-
"log"
1111
"os"
1212
"strings"
1313
)
1414

15+
var version string
16+
1517
func main() {
1618

19+
if len(os.Args) > 1 {
20+
if os.Args[1] == "-v" {
21+
fmt.Printf("awsenv version %s\n", version)
22+
os.Exit(0)
23+
}
24+
}
25+
26+
// Set log level if defind, default level info
27+
if os.Getenv("LOG_LEVEL") != "" {
28+
golog.SetLevel(os.Getenv("LOG_LEVEL"))
29+
}
30+
1731
keys := strings.Split(os.Getenv("SSM_PATH"), "/")
1832
params := make(map[string]string)
1933

@@ -26,7 +40,7 @@ func main() {
2640
// Loop through the sub paths and retrieve parameters
2741
for i := range keys {
2842
path = path + "/" + keys[i]
29-
log.Printf("Retriving parameters in path %s", path)
43+
golog.Infof("Retriving parameters in path %s", path)
3044
ExportVariables(path, "", params)
3145
}
3246

@@ -53,11 +67,12 @@ func ExportVariables(path string, nextToken string, params map[string]string ) {
5367
output, err := client.GetParametersByPath(input)
5468

5569
if err != nil {
56-
log.Panic(err)
70+
golog.Fatal(err)
5771
}
5872

5973
for _, element := range output.Parameters {
6074
env, value := TrimParameter(path, element)
75+
golog.Debugf("Found parameter %s in path %s", env, path)
6176
params[env] = value
6277
}
6378

@@ -90,14 +105,14 @@ func ParametersToFile(params map[string]string) {
90105
}
91106
// Create /ssm directory if it doesn't exist
92107
if _, err := os.Stat(dir); os.IsNotExist(err) {
93-
log.Printf("Creating directory %s", dir)
108+
golog.Debugf("Creating directory %s", dir)
94109
os.MkdirAll(dir, 0755)
95110
}
96111

97112
// Write evironment variables to .env file
98113
err := ioutil.WriteFile(dir + "/.env", buffer.Bytes(), 0744)
99114
if err != nil {
100-
log.Panic(err)
115+
golog.Fatal(err)
101116
}
102117
}
103118

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
build: ./
77
image: base2/awsenv
88
environment:
9+
LOG_LEVEL: debug
910
SSM_PATH: /my-app/production/prod1
1011
OUTPUT: shell
1112
AWS_REGION: ap-southeast-2

0 commit comments

Comments
 (0)