You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/11/07 21:01:05 UTC

[trafficcontrol] 01/04: Dockerized TO integration tests

This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 83361ff847fc4608c16438ee730a5bea74ce6177
Author: moltzaum <ma...@moltzau.net>
AuthorDate: Fri Oct 19 16:37:00 2018 -0600

    Dockerized TO integration tests
---
 .../cdn-in-a-box/docker-compose.totest.yml         | 66 +++++++++++++++++++++
 .../cdn-in-a-box/to_integration/Dockerfile         | 55 +++++++++++++++++
 .../cdn-in-a-box/to_integration/config.sh          | 68 ++++++++++++++++++++++
 infrastructure/cdn-in-a-box/to_integration/run.sh  | 40 +++++++++++++
 4 files changed, 229 insertions(+)

diff --git a/infrastructure/cdn-in-a-box/docker-compose.totest.yml b/infrastructure/cdn-in-a-box/docker-compose.totest.yml
new file mode 100644
index 0000000..23f6dbd
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/docker-compose.totest.yml
@@ -0,0 +1,66 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# To use this compose you should first build Traffic Ops and then copy the RPM to :
+#
+# trafficcontrol/infrastructure/cdn-in-a-box/traffic_ops/traffic_ops.rpm
+#
+#      cd trafficcontrol/infrastructure/cdn-in-a-box
+#
+# Adjust the settings in `variables.env` to suit your needs.
+#
+#      docker-compose up -d
+#
+# The Traffic Ops Go API will then be available on https://localhost:6443,
+# the Perl API on https://localhost:60443, and the postgres database on localhost 5432.
+#
+# Note that this setup is intended for testing and not for production use.
+
+---
+version: '2.1'
+
+networks:
+  tcnet:
+    driver: bridge
+    enable_ipv6: true
+    ipam:
+      driver: default
+      config:
+        - subnet: 172.16.239.0/24
+        - subnet: "fc01:9400:1000:8::/64"
+
+services:
+  integration:
+    build:
+      context: ../..
+      dockerfile: infrastructure/cdn-in-a-box/to_integration/Dockerfile
+    env_file: 
+      - variables.env
+    hostname: integration
+    domainname: infra.ciab.test
+    networks:
+      tcnet:
+        ipv4_address: 172.16.239.250
+        ipv6_address: "fc01:9400:1000:8::250"
+    volumes:
+      - shared:/shared
+      - ./dns/container-resolv.conf:/etc/resolv.conf
+
+volumes:
+    shared:
+        external: false
+ 
diff --git a/infrastructure/cdn-in-a-box/to_integration/Dockerfile b/infrastructure/cdn-in-a-box/to_integration/Dockerfile
new file mode 100644
index 0000000..0d9c7e0
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/to_integration/Dockerfile
@@ -0,0 +1,55 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+FROM golang:1.11 AS integration-builder
+
+# integration source and dependencies
+COPY ./lib/ /go/src/github.com/apache/trafficcontrol/lib/
+COPY ./vendor/ /go/src/github.com/apache/trafficcontrol/vendor/
+COPY ./traffic_ops/client/ /go/src/github.com/apache/trafficcontrol/traffic_ops/client/
+COPY ./traffic_ops/vendor/ /go/src/github.com/apache/trafficcontrol/traffic_ops/vendor/
+COPY ./infrastructure/cdn-in-a-box/to_integration/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/to_integration/
+COPY ./traffic_ops/testing/api /go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api
+COPY ./traffic_ops/traffic_ops_golang /go/src/github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang
+COPY ./infrastructure/cdn-in-a-box/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/
+
+# if we end up using a different versioning convention, the compile command will need to change
+WORKDIR /go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api
+RUN go get -u golang.org/x/net/publicsuffix golang.org/x/crypto/scrypt
+RUN go test -c ./v1* -o traffic_ops_integration
+
+FROM debian:stretch
+# Based off enroller. Might be able to remove some things from the install.
+RUN apt-get update && apt-get install -y netcat curl dnsutils net-tools vim && apt-get clean
+
+# MANIFEST
+# run.sh                    (wait on TO, then run bin)
+# to-access.sh              (sourced, get to-ping and env vars)
+# config.sh                 (sourced, and creates config for bin file)
+# tc-fixtures.json          (test data to run tests with)
+# traffic_ops_integration   (main bin, from integration-builder)
+COPY ./infrastructure/cdn-in-a-box/to_integration/run.sh    /opt/integration/app/
+COPY ./infrastructure/cdn-in-a-box/traffic_ops/to-access.sh /opt/integration/app/
+COPY ./infrastructure/cdn-in-a-box/to_integration/config.sh /opt/integration/app/
+COPY ./traffic_ops/testing/api/v14/tc-fixtures.json         /opt/integration/app/
+COPY --from=integration-builder \
+    /go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api/traffic_ops_integration \
+    /opt/integration/app/
+
+WORKDIR /opt/integration/app
+CMD ./run.sh
+
diff --git a/infrastructure/cdn-in-a-box/to_integration/config.sh b/infrastructure/cdn-in-a-box/to_integration/config.sh
new file mode 100755
index 0000000..c18eb11
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/to_integration/config.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Script for running the Dockerfile for Traffic Ops.
+# The Dockerfile sets up a Docker image which can be used for any new Traffic Ops container;
+# This script, which should be run when the container is run (it's the ENTRYPOINT), will configure the container.
+
+# Check that env vars are set
+envvars=( DB_SERVER DB_PORT DB_ROOT_PASS DB_USER DB_USER_PASS ADMIN_USER ADMIN_PASS DOMAIN TO_PERL_HOST TO_PERL_PORT TO_HOST TO_PORT TP_HOST)
+for v in $envvars
+do
+	if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+done
+
+cat <<-EOF >/opt/integration/app/traffic-ops-test.conf
+{
+    "default": {
+        "logLocations": {
+            "debug": "stdout",
+            "error": "stdout",
+            "event": "stdout",
+            "info": "stdout",
+            "warning": "stdout"
+        },
+        "session": {
+            "timeoutInSecs": 60
+        }
+    },
+    "trafficOps": {
+        "URL": "https://$TO_HOST:$TO_PORT",
+	    "password": "$ADMIN_PASS",
+        "users": {
+            "disallowed": "disallowed",
+            "operations": "operations",
+            "admin": "admin",
+            "federation": "federation",
+            "portal": "portal",
+            "readOnly": "readOnly"
+        }
+    },
+    "trafficOpsDB": {
+        "description": "Local PostgreSQL database on port 5432",
+        "dbname": "$DB_NAME",
+        "hostname": "$DB_FQDN",
+        "user": "$DB_USER",
+        "password": "$DB_USER_PASS",
+        "port": "$DB_PORT",
+        "ssl": false,
+        "type": "Pg"
+    }
+}
+EOF
+
diff --git a/infrastructure/cdn-in-a-box/to_integration/run.sh b/infrastructure/cdn-in-a-box/to_integration/run.sh
new file mode 100755
index 0000000..c6b36bd
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/to_integration/run.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Check that env vars are set
+envvars=( DB_SERVER DB_PORT DB_ROOT_PASS DB_USER DB_USER_PASS ADMIN_USER ADMIN_PASS)
+for v in $envvars
+do
+	if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+done
+
+source to-access.sh
+
+TO_URL="https://$TO_FQDN:$TO_PORT"
+while ! to-ping 2>/dev/null; do
+   echo waiting for trafficops
+   sleep 3
+done
+
+# if [[ -r ]]; then; source config.sh; done    traffic_ops/run.sh
+# if [[ -x ]]; then;./config.sh; done          traffic_ops/run-go.sh
+source config.sh
+
+./traffic_ops_integration -cfg=traffic-ops-test.conf
+exit $?
+