Skip to content

Commit c2d434a

Browse files
committed
feat: dockerize
1 parent 3945356 commit c2d434a

12 files changed

+42
-3
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ mailrelay
22
test
33
vendor
44
build
5+
.pytest_cache
6+
__pycache__

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
testContainers

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"args": []
1515
}
1616
]
17-
}
17+
}

.vscode/settings.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
"HELO",
55
"EHLO",
66
"gosec"
7-
]
8-
}
7+
],
8+
"python.testing.pytestArgs": [
9+
"tests"
10+
],
11+
"python.testing.unittestEnabled": true,
12+
"python.testing.pytestEnabled": true
13+
}

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.23 AS builder
2+
WORKDIR /app
3+
COPY src/* ./
4+
RUN go mod download && \
5+
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
6+
7+
FROM alpine:3.21
8+
RUN apk --no-cache add ca-certificates
9+
WORKDIR /root/
10+
COPY --from=builder /app/main /app/main
11+
COPY mailrelay.json /etc/mailrelay/mailrelay.json
12+
CMD ["/app/main", "-config", "/etc/mailrelay/mailrelay.json"]

auth.go src/auth.go

File renamed without changes.

client.go src/client.go

File renamed without changes.

go.mod src/go.mod

File renamed without changes.

go.sum src/go.sum

File renamed without changes.

main.go src/main.go

File renamed without changes.

server.go src/server.go

File renamed without changes.

tests/test_docker.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
import pytest
3+
from testcontainers.core.image import DockerImage
4+
from testcontainers.core.container import DockerContainer
5+
from testcontainers.core.waiting_utils import wait_for_logs
6+
7+
def test_docker_build():
8+
"""build and test the main container"""
9+
root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))
10+
print("Using root dir %s" % root)
11+
12+
# build image
13+
with DockerImage(path=root, tag="test-image") as image:
14+
logs = image.get_logs()
15+
print("build logs: %s" % logs)
16+
# run it
17+
with DockerContainer(str(image)) as container:
18+
delay = wait_for_logs(container, "Listening on TCP 0.0.0.0:")
19+
assert True

0 commit comments

Comments
 (0)