feat: deployment for weather server
This commit is contained in:
parent
fe8cc087c0
commit
81c20103bc
53
DockerfilePoller
Normal file
53
DockerfilePoller
Normal file
@ -0,0 +1,53 @@
|
||||
FROM --platform=$BUILDPLATFORM golang:1.16.0-alpine3.13 AS builder
|
||||
# ex. amd64
|
||||
ARG TARGETARCH
|
||||
# ex. linux/amd64
|
||||
ARG BUILDPLATFORM
|
||||
|
||||
RUN apk update && \
|
||||
apk add --no-cache git ca-certificates make tzdata gcc libc-dev && \
|
||||
apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing cfssl && \
|
||||
update-ca-certificates
|
||||
|
||||
ENV USER=appuser
|
||||
ENV UID=10001
|
||||
ENV GID=10001
|
||||
WORKDIR /data
|
||||
|
||||
RUN addgroup \
|
||||
--gid "${GID}" \
|
||||
"${USER}" && \
|
||||
adduser \
|
||||
--disabled-password \
|
||||
--gecos "" \
|
||||
--home "/nonexistent" \
|
||||
--shell "/sbin/nologin" \
|
||||
--no-create-home \
|
||||
--uid "${UID}" \
|
||||
-G "${USER}" \
|
||||
"${USER}"
|
||||
|
||||
COPY Makefile .
|
||||
COPY go.mod .
|
||||
COPY go.sum .
|
||||
RUN make dependencies
|
||||
|
||||
COPY . .
|
||||
RUN make build-poller \
|
||||
GOARCH=$TARGETARCH \
|
||||
GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) \
|
||||
GOBUILDFLAGS="-a -tags netgo -installsuffix netgo" \
|
||||
LDFLAGS="-w -s -d"
|
||||
|
||||
FROM scratch
|
||||
|
||||
USER appuser:appuser
|
||||
|
||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=builder /etc/passwd /etc/passwd
|
||||
COPY --from=builder /etc/group /etc/group
|
||||
COPY --from=builder --chown=appuser:appuser /data/bin/* /go/bin/poller
|
||||
|
||||
WORKDIR /go
|
||||
ENTRYPOINT ["/go/bin/poller"]
|
@ -35,12 +35,9 @@ COPY go.mod .
|
||||
COPY go.sum .
|
||||
RUN make dependencies
|
||||
|
||||
ARG BINARYNAME="poller"
|
||||
# ARG BINARYNAME="weather"
|
||||
|
||||
COPY . .
|
||||
# RUN make build-$BINARYNAME GOARCH=$TARGETARCH GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) LDFLAGS='-extldflags="-static"'
|
||||
RUN make build-$BINARYNAME \
|
||||
RUN make build-weather \
|
||||
GOARCH=$TARGETARCH \
|
||||
GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) \
|
||||
GOBUILDFLAGS="-a -tags netgo -installsuffix netgo" \
|
||||
@ -54,8 +51,8 @@ COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=builder /etc/passwd /etc/passwd
|
||||
COPY --from=builder /etc/group /etc/group
|
||||
COPY --from=builder --chown=appuser:appuser /data/bin/* /go/bin/poller
|
||||
COPY --from=builder --chown=appuser:appuser /data/bin/* /go/bin/weather
|
||||
COPY --from=builder --chown=appuser:appuser /data/certs/out/weather* /go
|
||||
|
||||
WORKDIR /go
|
||||
ENTRYPOINT ["/go/bin/poller"]
|
||||
ENTRYPOINT ["/go/bin/weather"]
|
13
Makefile
13
Makefile
@ -9,6 +9,8 @@ LDFLAGS=-w -s
|
||||
GOBUILDFLAGS=
|
||||
DOCKER_BUILDKIT=1
|
||||
CGO_ENABLED=0
|
||||
WEATHER_VERSION=latest
|
||||
POLLER_VERSION=latest
|
||||
|
||||
build: build-poller build-weather
|
||||
|
||||
@ -47,10 +49,13 @@ clean:
|
||||
get-root-ca:
|
||||
cfssl info -remote rasp1.localdomain:444 -config certs/client-config.json | cfssljson -bare -stdout /dev/stdout | tee certs/out/ca.pem
|
||||
|
||||
docker: docker-build docker-push
|
||||
docker: docker-build-poller docker-build-weather docker-push
|
||||
|
||||
docker-build:
|
||||
docker build -t docker.registry:5000/weather .
|
||||
docker-build-poller:
|
||||
docker build -t docker.registry:5000/weather/poller:$(POLLER_VERSION) -f DockerfilePoller .
|
||||
docker-build-weather:
|
||||
docker build -t docker.registry:5000/weather/server:$(WEATHER_VERSION) -f DockerfileWeather .
|
||||
|
||||
docker-push:
|
||||
docker push docker.registry:5000/weather
|
||||
docker push docker.registry:5000/weather/poller:$(POLLER_VERSION)
|
||||
docker push docker.registry:5000/weather/server:$(WEATHER_VERSION)
|
@ -53,6 +53,6 @@ func (w *weatherPoller) Poll() io.ReadCloser {
|
||||
//handleError generic fatal error
|
||||
func (w *weatherPoller) handleError(err error) {
|
||||
if err != nil {
|
||||
w.logger.Fatal("Poller error", zap.Error(err))
|
||||
w.logger.Error("Poller error", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,9 @@ func NewS3Storage(log *logger.WeatherLogger, config *WeatherS3StorageConfig, buc
|
||||
if config == nil {
|
||||
customConfig := CustomAwsConfig{}
|
||||
err := decodeFile(defaults.SharedConfigFilename(), &customConfig)
|
||||
s3.handleError(err)
|
||||
if err != nil {
|
||||
s3.logger.Fatal("Storage error", zap.Error(err))
|
||||
}
|
||||
|
||||
consolidateConfig = aws.Config{
|
||||
Endpoint: &customConfig.Default.EndpointURL,
|
||||
@ -77,7 +79,9 @@ func NewS3Storage(log *logger.WeatherLogger, config *WeatherS3StorageConfig, buc
|
||||
SharedConfigState: session.SharedConfigEnable,
|
||||
Config: consolidateConfig,
|
||||
})
|
||||
s3.handleError(err)
|
||||
if err != nil {
|
||||
s3.logger.Fatal("Storage error", zap.Error(err))
|
||||
}
|
||||
s3.session = s
|
||||
|
||||
return &s3
|
||||
@ -92,7 +96,9 @@ func (ss *s3Storage) Store(content io.Reader) {
|
||||
Key: aws.String(fmt.Sprintf("%s.json", time.Now().UTC().Format(time.RFC3339))),
|
||||
Body: content,
|
||||
})
|
||||
ss.handleError(err)
|
||||
if err != nil {
|
||||
ss.logger.Error("Storage error", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
//DecodeFile call toml.Decode with file
|
||||
@ -106,10 +112,3 @@ func decodeFile(fpath string, v interface{}) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//handleError generic fatal error
|
||||
func (ss *s3Storage) handleError(err error) {
|
||||
if err != nil {
|
||||
ss.logger.Fatal("Storage error", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ resource "kubernetes_deployment" "application" {
|
||||
container {
|
||||
image = format("%s:%s", var.application_image_tag, var.application_version)
|
||||
name = "poller-application"
|
||||
args = ["-filename", "/conf/config.hcl", "-logLevel", "info", "-logOutput", "/logs/weather.log"]
|
||||
args = ["-filename", "/conf/config.hcl", "-logLevel", "info", "-logOutput", "/logs/weather.log", "-check-interval", "1h"]
|
||||
volume_mount {
|
||||
mount_path = "/conf"
|
||||
name = local.config_volume_name
|
||||
|
@ -17,7 +17,7 @@ variable "S3_key_id" {
|
||||
description = "S3 backend key id"
|
||||
}
|
||||
variable "application_image_tag" {
|
||||
default = "docker.registry/weather"
|
||||
default = "docker.registry/weather/poller"
|
||||
description = "container tag deployed"
|
||||
}
|
||||
variable "application_version" {
|
||||
|
Loading…
Reference in New Issue
Block a user