FROM golang:1.26 AS build

ARG VERSION

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libsecret-1-dev \
    libfido2-dev \
    libcbor-dev \
    pass

# Build
ADD https://github.com/ProtonMail/proton-bridge.git#${VERSION} /build/proton-bridge/
WORKDIR /build/proton-bridge/
RUN sed -i 's/127.0.0.1/0.0.0.0/g' internal/constants/constants.go
RUN set -eux; \
    make build-nogui vault-editor

FROM alpine:latest

EXPOSE 1025/tcp
EXPOSE 1143/tcp

RUN mkdir -p /root/.gnupg && chmod 700 /root/.gnupg

# Install dependencies and protonmail bridge
RUN apk add --no-cache \
    gcompat \
    libsecret \
    libfido2 \
    gnupg pass ca-certificates

# Copy bash scripts
COPY gpgparams entrypoint.sh /protonmail/
WORKDIR /protonmail/

# Copy protonmail
COPY --from=build /build/proton-bridge/bridge /usr/bin/
COPY --from=build /build/proton-bridge/proton-bridge /usr/bin/
COPY --from=build /build/proton-bridge/vault-editor /usr/bin/

ENTRYPOINT ["bash", "/protonmail/entrypoint.sh"]
