VERSION 0.8
PROJECT earthly-technologies/core
FROM --pass-args ..+base

IMPORT .. AS tests

RUN apk add bash
WORKDIR /test

test-dockerhub:
    COPY lock.sh unlock.sh \
        test-dockerhub-project.sh test-dockerhub-user.sh \
        .
    RUN --secret EARTHLY_TOKEN=fake-user-write-token \
        --secret AWS_ACCESS_KEY_ID=aws/ci-cd-access-key \
        --secret AWS_SECRET_ACCESS_KEY=aws/ci-cd-access-secret \
        ./lock.sh && ( \
            ./test-dockerhub-user.sh && \
            ./test-dockerhub-project.sh && \
            true) || ( ./unlock.sh && echo "dockerhub test failed"; exit 1) && ./unlock.sh

test-ecr:
    COPY lock.sh unlock.sh \
        test-ecr.sh \
        test-ecr-project.sh test-ecr-user.sh \
        .

    ENV EARTHLY_EXEC_CMD=/test/test-ecr.sh
    RUN --secret EARTHLY_TOKEN=fake-user-write-token \
        --secret AWS_ACCESS_KEY_ID=aws/ci-cd-access-key \
        --secret AWS_SECRET_ACCESS_KEY=aws/ci-cd-access-secret \
        --mount=type=tmpfs,target=/tmp/earthly \
        --privileged \
        --entrypoint \
        --mount=type=tmpfs,target=/tmp/earthly

test-gcp:
    COPY lock.sh unlock.sh \
        test-gcp.sh \
        test-gcp-project.sh test-gcp-user.sh \
        .

    ENV EARTHLY_EXEC_CMD=/test/test-gcp.sh
    RUN --secret EARTHLY_TOKEN=fake-user-write-token \
        --secret GCP_KEY=gcp/ci-cd-key \
        --mount=type=tmpfs,target=/tmp/earthly \
        --privileged \
        --entrypoint \
        --mount=type=tmpfs,target=/tmp/earthly

test-multi:
    COPY lock.sh unlock.sh \
        test-multi.sh \
        .

    ENV EARTHLY_EXEC_CMD=/test/test-multi.sh
    RUN --secret EARTHLY_TOKEN=fake-user-write-token \
        --secret GCP_KEY=gcp/ci-cd-key \
        --secret AWS_ACCESS_KEY_ID=aws/ci-cd-access-key \
        --secret AWS_SECRET_ACCESS_KEY=aws/ci-cd-access-secret \
        --mount=type=tmpfs,target=/tmp/earthly \
        --privileged \
        --entrypoint \
        --mount=type=tmpfs,target=/tmp/earthly

test:
    BUILD +test-dockerhub
    BUILD +test-ecr
    BUILD +test-gcp
    BUILD +test-multi
