Use docker-compose instead of a shell script (#155)
This commit is contained in:
37
.github/workflows/acctest.yml
vendored
37
.github/workflows/acctest.yml
vendored
@@ -9,7 +9,6 @@ on:
|
||||
schedule:
|
||||
- cron: '0 13 * * *'
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
@@ -20,18 +19,12 @@ jobs:
|
||||
uses: actions/setup-go@v2.1.4
|
||||
with:
|
||||
go-version: '1.16'
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go mod download
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
go build -v .
|
||||
run: make build
|
||||
|
||||
test:
|
||||
name: Matrix Test
|
||||
@@ -41,13 +34,13 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
version:
|
||||
unifi_version:
|
||||
- 'stable-5'
|
||||
- '6.0'
|
||||
- '6.1'
|
||||
- '6.2'
|
||||
- 'v6'
|
||||
terraform:
|
||||
terraform_version:
|
||||
- '0.15.5'
|
||||
- '1.0.6'
|
||||
steps:
|
||||
@@ -56,30 +49,14 @@ jobs:
|
||||
uses: actions/setup-go@v2.1.4
|
||||
with:
|
||||
go-version: '1.16'
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
# TODO: convert this to `services`
|
||||
- name: Start Unifi controller
|
||||
run: |
|
||||
./controller.sh start ${{ matrix.version }}
|
||||
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go mod download
|
||||
|
||||
- run: make testacc-up UNIFI_VERSION=${{ matrix.unifi_version }}
|
||||
|
||||
- name: TF acceptance tests
|
||||
timeout-minutes: 10
|
||||
env:
|
||||
TF_ACC: "1"
|
||||
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
|
||||
run: make testacc TF_ACC_TERRAFORM_VERSION=${{ matrix.terraform_version }}
|
||||
|
||||
UNIFI_USERNAME: tfacctest
|
||||
UNIFI_PASSWORD: tfacctest1234
|
||||
UNIFI_API: https://localhost:8443/
|
||||
UNIFI_ACC_WLAN_CONCURRENCY: "4"
|
||||
UNIFI_INSECURE: 'true'
|
||||
run: |
|
||||
go test -v -cover ./internal/provider/
|
||||
- run: make testacc-down
|
||||
|
||||
39
Makefile
39
Makefile
@@ -1,20 +1,33 @@
|
||||
export UNIFI_VERSION ?= v6
|
||||
export UNIFI_USERNAME ?= tfacctest
|
||||
export UNIFI_EMAIL ?= tfacctest@example.com
|
||||
export UNIFI_PASSWORD ?= tfacctest1234
|
||||
|
||||
NAME=terraform-provider-unifi
|
||||
PLUGIN_PATH=$(HOME)/.terraform.d/plugins
|
||||
TEST ?= ./...
|
||||
TESTARGS ?=
|
||||
|
||||
all: build
|
||||
.PHONY: default
|
||||
default: build
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
go build -o $(NAME)
|
||||
go install
|
||||
|
||||
.PHONY: testacc
|
||||
testacc:
|
||||
TF_ACC=1 UNIFI_ACC_WLAN_CONCURRENCY=4 UNIFI_API=https://localhost:8443 UNIFI_INSECURE=true go test $(TEST) -v $(TESTARGS)
|
||||
|
||||
install: build
|
||||
install -d $(PLUGIN_PATH)
|
||||
install -m 775 $(NAME) $(PLUGIN_PATH)/
|
||||
.PHONY: testacc-up
|
||||
testacc-up:
|
||||
docker-compose up --detach unifi
|
||||
|
||||
test:
|
||||
./controller.sh update
|
||||
./controller.sh start
|
||||
./controller.sh test
|
||||
./controller.sh stop
|
||||
./controller.sh reset
|
||||
@echo -n "Waiting for container"
|
||||
@until test -n "$$(docker ps --filter id=$$(docker-compose ps --quiet unifi) --filter health=healthy --quiet)"; do echo -n .; sleep 1; done
|
||||
@echo
|
||||
|
||||
@echo "Bootstrapping Unifi controller"
|
||||
docker-compose up --abort-on-container-exit bootstrap
|
||||
|
||||
.PHONY: testacc-down
|
||||
testacc-down:
|
||||
docker-compose down
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -eou pipefail
|
||||
|
||||
default_tag="stable-6"
|
||||
|
||||
# Local Administrator
|
||||
# Username: tfacctest
|
||||
# Password: tfacctest1234
|
||||
# Email: tfacctest@example.com
|
||||
DOCKER_HTTP_PORT="${DOCKER_HTTP_PORT:-8080}"
|
||||
DOCKER_HTTPS_PORT="${DOCKER_HTTPS_PORT:-8443}"
|
||||
DOCKER_STUN_PORT="${DOCKER_STUN_PORT:-3478}"
|
||||
DOCKER_AIRCONTROL_PORT="${DOCKER_AIRCONTROL_PORT:-10001}"
|
||||
|
||||
if test $# -eq 0; then
|
||||
echo "please specify either 'start' or 'test'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
"start")
|
||||
docker run --rm --init -d \
|
||||
-p ${DOCKER_HTTP_PORT}:8080 \
|
||||
-p ${DOCKER_HTTPS_PORT}:8443 \
|
||||
-p ${DOCKER_STUN_PORT}:3478/udp \
|
||||
-p ${DOCKER_AIRCONTROL_PORT}:10001/udp \
|
||||
-e TZ='America/New_York' \
|
||||
--name unifi \
|
||||
jacobalberty/unifi:${2:-$default_tag}
|
||||
|
||||
echo "Waiting for login page..."
|
||||
timeout 300 bash -c 'while [[ "$(curl --insecure --location -s -o /dev/null -w "%{http_code}" '"https://localhost:${DOCKER_HTTPS_PORT}/manage/account/login"')" != "200" ]]; do sleep 5; done'
|
||||
echo "Controller running."
|
||||
|
||||
echo "Bootstrapping controller..."
|
||||
function unifi_curl() {
|
||||
curl --data "${2}" --header 'Content-Type application/json' --insecure "https://localhost:${DOCKER_HTTPS_PORT}${1}"
|
||||
}
|
||||
unifi_curl /api/cmd/sitemgr '{"cmd":"add-default-admin","name":"tfacctest","email":"tfacctest@example.com","x_password":"tfacctest1234"}'
|
||||
unifi_curl /api/set/setting/super_identity '{"name":"UniFi Network"}'
|
||||
unifi_curl /api/cmd/system '{"cmd":"set-installed"}'
|
||||
;;
|
||||
"test")
|
||||
TF_ACC=1 \
|
||||
UNIFI_USERNAME=tfacctest \
|
||||
UNIFI_PASSWORD=tfacctest1234 \
|
||||
UNIFI_API="https://localhost:${DOCKER_HTTPS_PORT}/" \
|
||||
UNIFI_ACC_WLAN_CONCURRENCY="4" \
|
||||
UNIFI_INSECURE="true" \
|
||||
go test -v -cover -count 1 ./internal/provider
|
||||
;;
|
||||
"stop")
|
||||
docker stop unifi
|
||||
;;
|
||||
"update")
|
||||
docker pull jacobalberty/unifi:${2:-$default_tag}
|
||||
;;
|
||||
*)
|
||||
echo "unrecognized command"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
31
docker-compose.yaml
Normal file
31
docker-compose.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
services:
|
||||
unifi:
|
||||
image: 'jacobalberty/unifi:${UNIFI_VERSION:?}'
|
||||
init: true
|
||||
restart: 'always'
|
||||
user: 'unifi'
|
||||
ports:
|
||||
- '${UNIFI_HTTP_PORT:-8080}:8080/tcp'
|
||||
- '${UNIFI_HTTPS_PORT:-8443}:8443/tcp'
|
||||
|
||||
bootstrap:
|
||||
image: 'alpine/httpie'
|
||||
depends_on:
|
||||
unifi:
|
||||
condition: 'service_healthy'
|
||||
entrypoint: '/bin/sh'
|
||||
command:
|
||||
- '-c'
|
||||
- |
|
||||
alias http='http --quiet --check-status --verify=no --ignore-stdin'
|
||||
|
||||
http https://unifi:8443/manage/account/login 2>/dev/null
|
||||
case $$? in
|
||||
0) echo 'Unifi controller has already been setup' >&2; exit 0;;
|
||||
3) echo 'Bootstrapping Unifi controller';;
|
||||
*) echo 'Unexpected HTTP response from Unifi controller' >&2; exit 1;;
|
||||
esac
|
||||
|
||||
http https://unifi:8443/api/cmd/sitemgr cmd=add-default-admin "name=${UNIFI_USERNAME:?}" "email=${UNIFI_EMAIL:?}" "x_password=${UNIFI_PASSWORD:?}"
|
||||
http https://unifi:8443/api/cmd/system cmd=set-installed
|
||||
Reference in New Issue
Block a user