FROM golang:1.18-alpine

ARG app_env=production
ARG commit_hash
ARG git_access_token
LABEL maintainer="shenjing.zhao@pingcap.com"
LABEL commit_hash="${commit_hash}"
LABEL app="security"
LABEL component="alert-server"
ENV GIN_MODE="release"
ENV GOPRIVATE="github.com/pingcap-inc/pchub"
WORKDIR /apps

# Update the package list and install pkg-config and libpcre3-dev using apk
RUN apk update && apk add --no-cache build-base pkgconf pcre-dev git

# Configure git to use an access token
RUN git config --global url.https://${git_access_token}@github.com/.insteadOf https://github.com/

# Install Go modules
COPY go.mod ./
COPY go.sum ./
RUN go mod tidy

# Copy the rest of the application source code
COPY . ./

# Build the Go application
RUN go build -o . /apps/cmd/alert-server

# Define the volume for configuration and logs
VOLUME [ "/apps/config", "/apps/logs" ]

# Expose the application port
EXPOSE 8867

# Define the entrypoint for the container
ENTRYPOINT ["/apps/alert-server", "-c=/apps/config/config-prod.yaml"]