terraform-provider-docker/scripts/testing/setup_private_registry.sh
Manuel Vogel d7038e7560 Feat/swarm 3 acc test infra (#39)
* Set up test infrastructure with local registry and custom images.

* Updated travis docker version and usage of new test infra.

* Made acc tests constantly output test results.

* Tmp acc test files are ignored.

* Fixed tests with new infra.

* Allowing insecure registries for acc tests. Added fallback for v1 registries.

* Added private image cleanup after tests.

* Refined acc test structure to confirm tf provider standards with make testacc.
2018-02-09 13:11:30 -06:00

38 lines
1.5 KiB
Bash
Executable file

set -e
# Create private registry
## Create self signed certs
mkdir -p scripts/testing/certs
openssl req \
-newkey rsa:2048 \
-nodes \
-x509 \
-days 365 \
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=127.0.0.1" \
-keyout scripts/testing/certs/registry_auth.key \
-out scripts/testing/certs/registry_auth.crt
## Create auth
mkdir -p scripts/testing/auth
# Start registry
docker run --entrypoint htpasswd registry:2 -Bbn testuser testpwd > scripts/testing/auth/htpasswd
docker run -d -p 5000:5000 --rm --name private_registry \
-v "$(pwd)"/scripts/testing/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
-v "$(pwd)"/scripts/testing/certs:/certs \
-e "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry_auth.crt" \
-e "REGISTRY_HTTP_TLS_KEY=/certs/registry_auth.key" \
registry:2
# wait a bit for travis...
sleep 5
# Login to private registry
docker login -u testuser -p testpwd 127.0.0.1:5000
# Build private images
docker build -t my-private-service ./scripts/testing -f ./scripts/testing/Dockerfile_v1
docker tag my-private-service 127.0.0.1:5000/my-private-service:v1
docker build -t my-private-service ./scripts/testing -f ./scripts/testing/Dockerfile_v2
docker tag my-private-service 127.0.0.1:5000/my-private-service:v2
# Push private images into private registry
docker push 127.0.0.1:5000/my-private-service:v1
docker push 127.0.0.1:5000/my-private-service:v2