Skip to content

Commit c94c0c7

Browse files
committed
Add logging
1 parent dcc7b5f commit c94c0c7

File tree

4 files changed

+52
-33
lines changed

4 files changed

+52
-33
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.idea
2+
.gitignore
3+
.github
4+
.dockerignore
5+
.git
6+
charts
7+
LICENSE
8+
README.md
9+
Makefile
10+
Dockerfile

Dockerfile

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
FROM golang:1.16-alpine AS build
2-
RUN apk add --no-cache git curl ca-certificates socat bash openssl
32
WORKDIR /workspace
43
COPY go.mod .
54
COPY go.sum .
65
RUN go mod download
76
COPY . .
8-
RUN curl -fsSL https://get.acme.sh | sh
97
RUN CGO_ENABLED=0 go build -o webhook -ldflags '-w -extldflags "-static"' .
108

11-
FROM alpine
12-
WORKDIR /root
13-
COPY --from=build /workspace/webhook /usr/local/bin/webhook
14-
COPY --from=build /root/.acme.sh /root/.acme.sh
15-
ADD acme_delegate.sh /root/acme_delegate.sh
16-
RUN apk add --no-cache ca-certificates curl socat bash openssl && chmod 755 /root/acme_delegate.sh
9+
FROM neilpang/acme.sh
1710

18-
ENTRYPOINT ["webhook"]
11+
RUN apk add bash
12+
13+
ARG DOCKER_APP_UID="1000"
14+
ARG DOCKER_APP_GID="1000"
15+
16+
####
17+
#### User/Group
18+
####
19+
20+
RUN set -eux \
21+
&& addgroup -g ${DOCKER_APP_GID} app \
22+
&& adduser -u ${DOCKER_APP_UID} -G app -s /bin/sh -D app \
23+
&& true
24+
25+
26+
RUN set -eux \
27+
&& mv /root/.acme.sh /opt/.acme.sh \
28+
&& chown -R app:app /opt/.acme.sh \
29+
&& chown -R app:app /acme.sh \
30+
&& true
31+
32+
33+
COPY --from=build --chown=app:app --chmod=777 /workspace/webhook /usr/local/bin/webhook
34+
COPY --chown=app:app --chmod=777 acme_delegate.sh /usr/local/bin/acme_delegate.sh
35+
36+
37+
USER app
38+
39+
ENTRYPOINT ["/usr/local/bin/webhook"]
40+
CMD [""]

acme_delegate.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

33
echo '__________________________ acme_delegate initialize __________________________'
4-
export HOME=/root
4+
export HOME=/opt
55
export DEBUG=3
6-
cd /root
6+
cd /opt
77
export
88

99
echo '__________________________ acme.sh environments __________________________'
@@ -14,8 +14,8 @@ dosk_txtvalue="$4"
1414
dosk_lasterror=""
1515

1616
echo '__________________________ acme.sh delegate __________________________'
17-
source /root/.acme.sh/acme.sh --info
18-
source /root/.acme.sh/dnsapi/${dosk_dnsapi}.sh
17+
source /opt/.acme.sh/acme.sh --info
18+
source /opt/.acme.sh/dnsapi/${dosk_dnsapi}.sh
1919
${dosk_dnsapi}_${dosk_action} "$dosk_fulldomain" "$dosk_txtvalue"
2020
retval=$?
2121

main.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
const (
2424
defaultTTL = 600
25-
acmeDelegate = "/acme_delegate.sh"
25+
acmeDelegate = "/usr/local/bin/acme_delegate.sh"
2626
acmeReturnValue = "ACME_RETVAL"
2727
)
2828

@@ -74,16 +74,9 @@ func (c *customDNSProviderSolver) DoDNSAPI(action string, ch *v1alpha1.Challenge
7474
return err
7575
}
7676

77-
envData, ok := envSecret.Data["env"]
78-
if !ok {
79-
klog.Errorf("Missing 'env' key in secret")
80-
return fmt.Errorf("no env in secret")
81-
}
82-
83-
env := envFromSecret{}
84-
if err := json.Unmarshal(envData, &env); err != nil {
85-
klog.Errorf("Failed to unmarshal env data: %v", err)
86-
return err
77+
envVars := []string{}
78+
for key, val := range envSecret.Data {
79+
envVars = append(envVars, fmt.Sprintf("%s=%s", key, string(val)))
8780
}
8881

8982
uuid := uuid.New()
@@ -96,18 +89,12 @@ func (c *customDNSProviderSolver) DoDNSAPI(action string, ch *v1alpha1.Challenge
9689

9790
procAttr := &os.ProcAttr{
9891
Files: []*os.File{os.Stdin, stdoutFile, os.Stderr},
99-
Env: env,
100-
}
101-
102-
dir, err := os.Getwd()
103-
if err != nil {
104-
klog.Errorf("Failed to get working directory: %v", err)
105-
return err
92+
Env: envVars,
10693
}
10794

10895
klog.Infof("Executing %s with action=%s", acmeDelegate, action)
109-
process, err := os.StartProcess(dir+acmeDelegate, []string{
110-
dir + acmeDelegate, cfg.DNSAPI, action, util.UnFqdn(ch.ResolvedFQDN), ch.Key,
96+
process, err := os.StartProcess(acmeDelegate, []string{
97+
acmeDelegate, cfg.DNSAPI, action, util.UnFqdn(ch.ResolvedFQDN), ch.Key,
11198
}, procAttr)
11299
if err != nil {
113100
klog.Errorf("Failed to start process: %v", err)

0 commit comments

Comments
 (0)