This repository was archived by the owner on Mar 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +85
-37
lines changed Expand file tree Collapse file tree 8 files changed +85
-37
lines changed Original file line number Diff line number Diff line change 1
1
acorn-dns
2
2
acorn.sqlite
3
+ .env
Original file line number Diff line number Diff line change @@ -18,14 +18,24 @@ args: {
18
18
containers: {
19
19
"acorn-dns": {
20
20
if args.dbHost == "db" {
21
- dependsOn: "db"
21
+ dependsOn: "db"
22
22
}
23
+
23
24
build: {
24
25
buildArgs: {
25
26
TAG: args.tag
26
27
}
27
28
context: "."
28
29
}
30
+
31
+ // Setup hot-reloading for api-server
32
+ if args.dev {
33
+ workdir: "/app"
34
+ image: "docker.io/cosmtrek/air" // https://github.com/cosmtrek/air
35
+ dirs: "/app": "./"
36
+ cmd: "api-server"
37
+ }
38
+
29
39
scale: args.scale
30
40
ports: "4315/http"
31
41
env: {
@@ -38,42 +48,45 @@ containers: {
38
48
ACORN_ROUTE53_ZONE_ID: args.route53ZoneId
39
49
AWS_ACCESS_KEY_ID: "secret://aws-creds/access-key?onchange=no-action"
40
50
AWS_SECRET_ACCESS_KEY: "secret://aws-creds/secret-key?onchange=no-action"
51
+ AWS_SESSION_TOKEN: "secret://aws-creds/session-token?onchange=no-action"
41
52
}
42
53
},
43
54
if args.dbHost == "db" {
44
- db: {
45
- image: "mariadb:10.7.4"
46
- env: {
47
- MARIADB_ROOT_PASSWORD: "secret://root-credentials/password?onchange=no-action"
48
- MARIADB_USER: "secret://db-user-credentials/username?onchange=no-action"
49
- MARIADB_PASSWORD: "secret://db-user-credentials/password?onchange=no-action"
50
- MARIADB_DATABASE: args.dbName
55
+ db: {
56
+ image: "mariadb:10.7.4"
57
+ env: {
58
+ MARIADB_ROOT_PASSWORD: "secret://root-credentials/password?onchange=no-action"
59
+ MARIADB_USER: "secret://db-user-credentials/username?onchange=no-action"
60
+ MARIADB_PASSWORD: "secret://db-user-credentials/password?onchange=no-action"
61
+ MARIADB_DATABASE: args.dbName
62
+ }
63
+ ports: "3306/tcp"
51
64
}
52
- ports: "3306/tcp"
53
- }
54
65
}
55
66
}
56
67
57
68
secrets: {
58
69
if args.dbHost == "db" {
59
- "root-credentials": {
60
- type: "basic"
61
- data: {
62
- username: "root"
70
+ "root-credentials": {
71
+ type: "basic"
72
+ data: {
73
+ username: "root"
74
+ }
63
75
}
64
- }
65
- "db-user-credentials": {
66
- type: "basic"
67
- data: {
68
- username: "acorn"
76
+ "db-user-credentials": {
77
+ type: "basic"
78
+ data: {
79
+ username: "acorn"
80
+ }
69
81
}
70
82
}
71
- }
83
+
72
84
"aws-creds": {
73
85
type: "opaque"
74
86
data: {
75
87
"access-key": ""
76
88
"secret-key": ""
89
+ "session-token": ""
77
90
}
78
91
}
79
92
}
Original file line number Diff line number Diff line change @@ -21,3 +21,6 @@ validate:
21
21
22
22
test :
23
23
go test ./...
24
+
25
+ dev :
26
+ ./scripts/dev.sh
Original file line number Diff line number Diff line change @@ -33,7 +33,5 @@ OPTIONS:
33
33
--db-port value Database port [$ACORN_DB_PORT]
34
34
--log-level value, -l value Log Level (default: "info") [$LOGLEVEL]
35
35
--log-caller log the caller (aka line number and file) (default: false)
36
- --log-disable-color disable log coloring (default: false)
37
- --log-full-timestamp force log output to always show full timestamp (default: false)
38
36
--help, -h show help (default: false)
39
37
```
Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ import (
5
5
"path"
6
6
7
7
"github.com/acorn-io/acorn-dns/pkg/commands"
8
- _ "github.com/acorn-io/acorn-dns/pkg/commands"
9
8
"github.com/acorn-io/acorn-dns/pkg/version"
10
9
"github.com/sirupsen/logrus"
11
10
"github.com/urfave/cli/v2"
12
11
)
13
12
14
13
func main () {
14
+ logrus .SetFormatter (& logrus.JSONFormatter {})
15
15
defer func () {
16
16
if r := recover (); r != nil {
17
17
// log panics forces exit
Original file line number Diff line number Diff line change 1
1
package apiserver
2
2
3
3
import (
4
+ "fmt"
4
5
"net"
5
6
"net/http"
6
7
"runtime/debug"
@@ -70,12 +71,19 @@ func loggingMiddleware(logger *logrus.Entry) func(http.Handler) http.Handler {
70
71
next .ServeHTTP (wrapped , r )
71
72
72
73
if ! strings .Contains (r .URL .EscapedPath (), "healthz" ) {
73
- logger .WithFields (logrus.Fields {
74
+ requestLogger := logger .WithFields (logrus.Fields {
74
75
"status" : wrapped .status ,
75
76
"method" : r .Method ,
76
77
"path" : r .URL .EscapedPath (),
77
78
"duration" : time .Since (start ),
78
- }).Infof ("handled: %d" , wrapped .status )
79
+ })
80
+
81
+ msg := fmt .Sprintf ("handled: %d" , wrapped .status )
82
+ if wrapped .status >= 400 {
83
+ requestLogger .Error (msg )
84
+ } else {
85
+ requestLogger .Debug (msg )
86
+ }
79
87
}
80
88
}
81
89
Original file line number Diff line number Diff line change @@ -22,24 +22,14 @@ func GlobalFlags() []cli.Flag {
22
22
Name : "log-caller" ,
23
23
Usage : "log the caller (aka line number and file)" ,
24
24
},
25
- & cli.BoolFlag {
26
- Name : "log-disable-color" ,
27
- Usage : "disable log coloring" ,
28
- },
29
- & cli.BoolFlag {
30
- Name : "log-full-timestamp" ,
31
- Usage : "force log output to always show full timestamp" ,
32
- },
33
25
}
34
26
35
27
return globalFlags
36
28
}
37
29
38
30
func Before (c * cli.Context ) error {
39
- formatter := & logrus.TextFormatter {
40
- DisableColors : c .Bool ("log-disable-color" ),
41
- FullTimestamp : c .Bool ("log-full-timestamp" ),
42
- }
31
+ formatter := & logrus.JSONFormatter {}
32
+
43
33
if c .Bool ("log-caller" ) {
44
34
logrus .SetReportCaller (true )
45
35
Original file line number Diff line number Diff line change
1
+ # Ensure that the AWS credentials are set before proceeding
2
+ if [ -z " $AWS_ACCESS_KEY_ID " ]; then
3
+ echo " AWS_ACCESS_KEY_ID is not set, please set it and try again"
4
+ exit 1
5
+ fi
6
+ if [ -z " $AWS_SECRET_ACCESS_KEY " ]; then
7
+ echo " AWS_SECRET_ACCESS_KEY is not set, please set it and try again"
8
+ exit 1
9
+ fi
10
+ if [ -z " $AWS_SESSION_TOKEN " ]; then
11
+ echo " AWS_SESSION_TOKEN is not set, please set it and try again"
12
+ exit 1
13
+ fi
14
+
15
+ # Replace the current aws-creds secret if it exists
16
+ acorn secrets aws-creds > /dev/null 2>&1
17
+ if [ $? -eq 0 ]; then
18
+ echo " aws-creds secret already exists, deleting it..."
19
+ acorn secret rm aws-creds > /dev/null 2>&1
20
+ fi
21
+
22
+ acorn secret create aws-creds \
23
+ --data access-key=$AWS_ACCESS_KEY_ID \
24
+ --data secret-key=$AWS_SECRET_ACCESS_KEY \
25
+ --data session-token=$AWS_SESSION_TOKEN \
26
+ > /dev/null
27
+
28
+ # Ensure that the ROUTE53_ZONE_ID is set before proceeding
29
+ if [ -z " $ROUTE53_ZONE_ID " ]; then
30
+ echo " ROUTE53_ZONE_ID is not set, please set it and try again"
31
+ exit 1
32
+ fi
33
+
34
+ # Hand-off start to acorn and link the aws-creds secret
35
+ acorn dev -p 4315:4315 -s aws-creds:aws-creds . --route53-zone-id $ROUTE53_ZONE_ID
You can’t perform that action at this time.
0 commit comments