diff --git a/README.md b/README.md index ce5afbb..6edbae4 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,56 @@ The currently encouraged way to build these images is by using the * `additional_tags`: *Optional.* The path to a file with whitespace-separated list of tag values to tag the image with (in addition to the tag configured in `source`). + +## Development + +### Prerequisites + +* golang is *required* - version 1.11.x or above is required for go mod to work +* docker is *required* - version 17.06.x is tested; earlier versions may also + work. +* go mod is used for dependency management of the golang packages. + +### Running the tests + +The tests have been embedded with the `Dockerfile`; ensuring that the testing +environment is consistent across any `docker` enabled platform. When the docker +image builds, the test are run inside the docker container, on failure they +will stop the build. + +Run the tests with the following commands for both `alpine` and `ubuntu` images: + +```sh +docker build -t registry-image-resource -f dockerfiles/alpine/Dockerfile . +docker build -t registry-image-resource -f dockerfiles/ubuntu/Dockerfile . +``` + +#### Integration tests + +The integration requires 2 docker repos, one private and one public. The `docker build` +step requires setting `--build-args` so the integration will run. + +Run the tests with the following command: + +```sh +docker build . -t registry-image-resource -f dockerfiles/alpine/Dockerfile \ + --build-arg DOCKER_PRIVATE_USERNAME="some-username" \ + --build-arg DOCKER_PRIVATE_PASSWORD="some-password" \ + --build-arg DOCKER_PRIVATE_REPO="some/repo" \ + --build-arg DOCKER_PUSH_USERNAME="some-username" \ + --build-arg DOCKER_PUSH_PASSWORD="some-password" \ + --build-arg DOCKER_PUSH_REPO="some/repo" + +docker build . -t registry-image-resource -f dockerfiles/ubuntu/Dockerfile \ + --build-arg DOCKER_PRIVATE_USERNAME="some-username" \ + --build-arg DOCKER_PRIVATE_PASSWORD="some-password" \ + --build-arg DOCKER_PRIVATE_REPO="some/repo" \ + --build-arg DOCKER_PUSH_USERNAME="some-username" \ + --build-arg DOCKER_PUSH_PASSWORD="some-password" \ + --build-arg DOCKER_PUSH_REPO="some/repo" +``` + +### Contributing + +Please make all pull requests to the `master` branch and ensure tests pass +locally. diff --git a/Dockerfile b/dockerfiles/alpine/Dockerfile similarity index 100% rename from Dockerfile rename to dockerfiles/alpine/Dockerfile diff --git a/dockerfiles/ubuntu/Dockerfile b/dockerfiles/ubuntu/Dockerfile new file mode 100644 index 0000000..9260335 --- /dev/null +++ b/dockerfiles/ubuntu/Dockerfile @@ -0,0 +1,37 @@ +FROM concourse/golang-builder as builder +COPY . /src +WORKDIR /src +ENV CGO_ENABLED 0 +RUN go get -d ./... +RUN go build -o /assets/in ./cmd/in +RUN go build -o /assets/out ./cmd/out +RUN go build -o /assets/check ./cmd/check +RUN set -e; for pkg in $(go list ./...); do \ + go test -o "/tests/$(basename $pkg).test" -c $pkg; \ + done + +FROM ubuntu:bionic AS resource +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + tzdata \ + ca-certificates \ + unzip \ + zip \ + && rm -rf /var/lib/apt/lists/* +COPY --from=builder assets/ /opt/resource/ +RUN chmod +x /opt/resource/* + +FROM resource AS tests +COPY --from=builder /tests /tests +ADD . /docker-image-resource +ARG DOCKER_PRIVATE_USERNAME +ARG DOCKER_PRIVATE_PASSWORD +ARG DOCKER_PRIVATE_REPO +ARG DOCKER_PUSH_USERNAME +ARG DOCKER_PUSH_PASSWORD +ARG DOCKER_PUSH_REPO +RUN set -e; for test in /tests/*.test; do \ + $test -ginkgo.v; \ + done + +FROM resource