Skip to content

Commit 9a4ef0a

Browse files
committed
chore: Update go to 1.25 and add bats tests
1 parent 21494b6 commit 9a4ef0a

File tree

3 files changed

+170
-6
lines changed

3 files changed

+170
-6
lines changed

.github/workflows/build_and_publish.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ jobs:
3434
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
3535
-
3636
name: Login to DockerHub
37-
if: github.event_name != 'pull_request'
3837
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
3938
with:
4039
username: ${{ secrets.DOCKERHUB_USERNAME }}
4140
password: ${{ secrets.DOCKERHUB_TOKEN }}
4241
-
4342
name: Login to GHCR
44-
if: github.event_name != 'pull_request'
4543
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
4644
with:
4745
registry: ghcr.io
@@ -53,6 +51,18 @@ jobs:
5351
with:
5452
context: .
5553
platforms: linux/amd64,linux/arm64
56-
push: ${{ github.event_name != 'pull_request' }}
54+
push: true
5755
tags: ${{ steps.meta.outputs.tags }}
5856
labels: ${{ steps.meta.outputs.labels }}
57+
58+
-
59+
name: Install BATS
60+
run: |
61+
sudo apt-get update
62+
sudo apt-get install -y bats
63+
64+
-
65+
name: Run BATS tests
66+
run: |
67+
IMAGE_REF="${{ steps.meta.outputs.tags }}"
68+
IMAGE_NAME=$(echo "$IMAGE_REF" | head -n1) bats envplate.bats

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# syntax=docker/dockerfile:1
22
# Build docker-gen from scratch
3-
FROM golang:1.23-alpine AS ep-builder
3+
FROM golang:1.25-alpine AS ep-builder
44

5-
ARG VERSION=v1.0.3
5+
ARG VERSION=v1.0.4-rc.1
66

7-
ADD https://github.com/kreuzwerker/envplate.git#${VERSION} /build
7+
# Pinning at https://github.com/kreuzwerker/envplate/commit/ec00ede3ca03c6bbbe0412bf4b84eacdcdabba11
8+
ADD https://github.com/kreuzwerker/envplate.git#ec00ede3ca03c6bbbe0412bf4b84eacdcdabba11 /build
89

910
WORKDIR /build
1011

envplate.bats

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/usr/bin/env bats
2+
3+
# Setup and teardown
4+
setup() {
5+
export TEST_DIR=$(mktemp -d)
6+
export IMAGE_NAME="${IMAGE_NAME:-local/ep:latest}"
7+
}
8+
9+
teardown() {
10+
rm -rf "$TEST_DIR"
11+
}
12+
13+
@test "basic variable substitution" {
14+
echo 'Value: ${TEST_VAR}' > "$TEST_DIR/config.txt"
15+
16+
run docker run --rm \
17+
-e TEST_VAR=hello \
18+
-v "$TEST_DIR:/test" \
19+
"$IMAGE_NAME" \
20+
ep /test/config.txt
21+
22+
[ "$status" -eq 0 ]
23+
24+
result=$(cat "$TEST_DIR/config.txt")
25+
[ "$result" = "Value: hello" ]
26+
}
27+
28+
@test "default value handling" {
29+
echo 'Database: ${DB_HOST:-localhost}' > "$TEST_DIR/config.txt"
30+
31+
run docker run --rm \
32+
-v "$TEST_DIR:/test" \
33+
"$IMAGE_NAME" \
34+
ep /test/config.txt
35+
36+
[ "$status" -eq 0 ]
37+
38+
result=$(cat "$TEST_DIR/config.txt")
39+
[ "$result" = "Database: localhost" ]
40+
}
41+
42+
@test "backup creation" {
43+
echo 'Value: ${TEST_VAR}' > "$TEST_DIR/config.txt"
44+
45+
run docker run --rm \
46+
-e TEST_VAR=hello \
47+
-v "$TEST_DIR:/test" \
48+
"$IMAGE_NAME" \
49+
ep -b /test/config.txt
50+
51+
[ "$status" -eq 0 ]
52+
[ -f "$TEST_DIR/config.txt.bak" ]
53+
54+
# Original content should be in backup
55+
backup_content=$(cat "$TEST_DIR/config.txt.bak")
56+
[ "$backup_content" = "Value: \${TEST_VAR}" ]
57+
58+
# Processed content should be in original file
59+
processed_content=$(cat "$TEST_DIR/config.txt")
60+
[ "$processed_content" = "Value: hello" ]
61+
}
62+
63+
@test "strict mode fails on missing variables" {
64+
echo 'Value: ${MISSING_VAR}' > "$TEST_DIR/config.txt"
65+
66+
run docker run --rm \
67+
-v "$TEST_DIR:/test" \
68+
"$IMAGE_NAME" \
69+
ep -s /test/config.txt
70+
71+
[ "$status" -ne 0 ]
72+
}
73+
74+
@test "escaped variables are not processed" {
75+
echo 'Escaped: \${TEST_VAR}' > "$TEST_DIR/config.txt"
76+
77+
run docker run --rm \
78+
-e TEST_VAR=hello \
79+
-v "$TEST_DIR:/test" \
80+
"$IMAGE_NAME" \
81+
ep /test/config.txt
82+
83+
[ "$status" -eq 0 ]
84+
85+
result=$(cat "$TEST_DIR/config.txt")
86+
[ "$result" = "Escaped: \${TEST_VAR}" ]
87+
}
88+
89+
@test "dry run outputs to stdout" {
90+
echo 'Value: ${TEST_VAR}' > "$TEST_DIR/config.txt"
91+
92+
run docker run --rm \
93+
-e TEST_VAR=hello \
94+
-v "$TEST_DIR:/test" \
95+
"$IMAGE_NAME" \
96+
ep -d /test/config.txt
97+
98+
[ "$status" -eq 0 ]
99+
[[ "$output" =~ "Value: hello" ]]
100+
101+
# Original file should be unchanged
102+
original_content=$(cat "$TEST_DIR/config.txt")
103+
[ "$original_content" = "Value: \${TEST_VAR}" ]
104+
}
105+
106+
@test "multiple files with glob pattern" {
107+
echo 'env=${ENV}' > "$TEST_DIR/app.conf"
108+
echo 'environment=${ENV}' > "$TEST_DIR/db.conf"
109+
110+
run docker run --rm \
111+
-e ENV=production \
112+
-v "$TEST_DIR:/test" \
113+
"$IMAGE_NAME" \
114+
ep '/test/*.conf'
115+
116+
[ "$status" -eq 0 ]
117+
118+
app_result=$(cat "$TEST_DIR/app.conf")
119+
db_result=$(cat "$TEST_DIR/db.conf")
120+
[ "$app_result" = "env=production" ]
121+
[ "$db_result" = "environment=production" ]
122+
}
123+
124+
@test "exec functionality works" {
125+
echo 'Message: ${MESSAGE}' > "$TEST_DIR/output.txt"
126+
echo 'Message: ${MESSAGE}${MESSAGE}' > "$TEST_DIR/output_exec.txt"
127+
128+
run docker run --rm \
129+
-e MESSAGE=hello \
130+
-v "$TEST_DIR:/test" \
131+
"$IMAGE_NAME" \
132+
ep -b /test/output.txt -- /usr/local/bin/ep -d /test/output_exec.txt
133+
134+
[ "$status" -eq 0 ]
135+
[[ "$output" =~ "Message: hellohello" ]]
136+
}
137+
138+
@test "version information available" {
139+
run docker run --rm "$IMAGE_NAME" ep --help
140+
141+
[ "$status" -eq 0 ]
142+
[[ "$output" =~ "envplate" ]]
143+
}
144+
145+
@test "container uses scratch base (minimal size)" {
146+
run docker images "$IMAGE_NAME" --format "{{.Size}}"
147+
148+
[ "$status" -eq 0 ]
149+
# Size should be less than 20MB for a scratch-based image
150+
size_mb=$(echo "$output" | sed 's/MB//' | cut -d'.' -f1)
151+
[ -n "$size_mb" ]
152+
[ "$size_mb" -lt 20 ]
153+
}

0 commit comments

Comments
 (0)