Skip to content

Commit

Permalink
Merge pull request #3 from eexit/add-hc
Browse files Browse the repository at this point in the history
Add Docker image healthcheck
  • Loading branch information
eexit authored Jun 1, 2021
2 parents 7a21349 + 37af401 commit 5a4d2f1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
SERVER_HOST=
SERVER_PORT=8080
SERVER_SHUTDOWN_TIMEOUT=5
TRACEPARENT_HEADER=traceparent
SMTP_ADDR=smtp:1025
Expand Down
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM eexit/curl-healthchecker:v1.0.0 AS curl

FROM golang:1 AS builder
RUN update-ca-certificates
ARG version
Expand All @@ -13,7 +15,10 @@ RUN CGO_ENABLED=0 GOOS=${goos} GOARCH=${goarch} go build \
./cmd/http2smtp

FROM scratch
COPY --from=curl /curl /
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /http2smtp /
EXPOSE 8080
EXPOSE 80
HEALTHCHECK --interval=5s --timeout=1s --retries=3 \
CMD ["/curl", "-fIA", "cURL healthcheck", "http://127.0.0.1/healthcheck"]
CMD ["/http2smtp"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
version: v0.1.0+dev
env_file: .env
ports:
- 8080:8080
- 8080:80
depends_on:
smtp:
condition: service_started
Expand Down
4 changes: 2 additions & 2 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func New(

svr.svr = &serverWrapper{
&http.Server{
Addr: e.ServerHost + ":" + e.ServerPort,
Addr: ":80",
Handler: svr.Wrap(svr.Mux()),
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
Expand All @@ -96,7 +96,7 @@ func (a *API) Serve() error {
errch := make(chan error)

go func(errch chan error) {
a.logger.Info().Msgf("listening on %s:%s", a.env.ServerHost, a.env.ServerPort)
a.logger.Info().Msg("listening on :80")
if err := a.svr.ListenAndServe(); err != http.ErrServerClosed {
// Error starting the listener:
a.logger.Err(err).Msgf("server listening error: %s", err)
Expand Down
10 changes: 5 additions & 5 deletions internal/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import (
func TestNew(t *testing.T) {
got := New(
env.Bag{
ServerHost: "test",
ServerPort: "8080",
SMTPAddr: "smtp:25",
LogLevel: "info",
},
zerolog.New(ioutil.Discard),
&smtp.Stub{},
converter.NewProvider(),
)
want := &API{
env: env.Bag{
ServerHost: "test",
ServerPort: "8080",
SMTPAddr: "smtp:25",
LogLevel: "info",
},
logger: zerolog.New(ioutil.Discard),
smtpClient: &smtp.Stub{},
converterProvider: converter.NewProvider(),
svr: &serverWrapper{&http.Server{Addr: "test:8080"}},
svr: &serverWrapper{&http.Server{Addr: ":80"}},
}

if !reflect.DeepEqual(got.logger, want.logger) {
Expand Down
2 changes: 1 addition & 1 deletion internal/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func Test_provider_Get(t *testing.T) {
},
{
name: "requested converter exist when there are several converters",
converters: []Converter{&rfc5322{}, &Stub{}},
converters: []Converter{&Stub{}, &rfc5322{}},
cid: StubConverterID,
want: &Stub{},
wantErr: false,
Expand Down
4 changes: 0 additions & 4 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package env

// Bag holds all the config envvars
type Bag struct {
// ServerHost is the app hostname to listen for incoming HTTP requests from
ServerHost string `envconfig:"SERVER_HOST"`
// ServerPort is the app listening port
ServerPort string `envconfig:"SERVER_PORT" default:"8080"`
// ServerShutdownTimeout is a duration in seconds to graceful shutdown internal
// processes when the app has initiated a shutdown.
ServerShutdownTimeout int `envconfig:"SERVER_SHUTDOWN_TIMEOUT" default:"5"`
Expand Down

0 comments on commit 5a4d2f1

Please sign in to comment.