ARG BASE_IMAGE=meltano-base
FROM $BASE_IMAGE as builder

# Tell Chamber to use the account default KMS key, and where to find it
ENV AWS_REGION ap-southeast-2
ENV CHAMBER_KMS_KEY_ALIAS aws/ssm

# Install chamber
ENV chamber_version=2.10.6

RUN cd /usr/local/bin \
    && curl -L -o /usr/local/bin/chamber https://github.com/segmentio/chamber/releases/download/v${chamber_version}/chamber-v${chamber_version}-linux-amd64 \
    && chmod +x /usr/local/bin/chamber

# Resolving issues for Python 3.9
RUN cd /build \
	&& export BASE_SHA=$(git hash-object poetry.lock) \
	&& echo Building Meltano on $BASE_SHA

# Install any additional requirements (This contains the version of Meltano to install)
COPY ./requirements.txt . 
RUN pip install -r requirements.txt

#Create a base project directory
RUN cd / \
    && meltano init project \
	&& cd / project

WORKDIR /project

# Install all plugins into the `.meltano` directory
COPY ./meltano.yml .
RUN meltano install

# Pin `discovery.yml` manifest by copying cached version to project root
RUN cp -n .meltano/cache/discovery.yml . 2>/dev/null || :

# Don't allow changes to containerized project files
ENV MELTANO_PROJECT_READONLY 1

ENTRYPOINT []