mirror of
https://github.com/linuxserver/docker-ci.git
synced 2026-02-04 18:50:13 +08:00
adding a basic readme and needed functionality for using against all of our web apps
This commit is contained in:
parent
195ec8ed9e
commit
297eaeb4f7
45
README.md
45
README.md
@ -2,13 +2,46 @@
|
||||
[forumurl]: https://forum.linuxserver.io
|
||||
[ircurl]: https://www.linuxserver.io/irc/
|
||||
[podcasturl]: https://www.linuxserver.io/podcast/
|
||||
[huburl]: https://hub.docker.com/r/linuxserver/ci/
|
||||
[pipelineurl]: https://github.com/linuxserver/pipeline-triggers
|
||||
|
||||
[][linuxserverurl]
|
||||
[][linuxserverurl]
|
||||
|
||||
## This is a Container in active development by the [LinuxServer.io][linuxserverurl] team and is not recommended for use by the general public.
|
||||
|
||||
If you want to comment\contribute on this container , are looking for support on any of our other work , or are curious about us in general, check out the following.
|
||||
## Contact information:-
|
||||
|
||||
* [forum.linuxserver.io][forumurl]
|
||||
* [IRC][ircurl] on freenode at `#linuxserver.io`
|
||||
* [Podcast][podcasturl] covers everything to do with getting the most from your Linux Server plus a focus on all things Docker and containerisation!
|
||||
| Type | Address/Details |
|
||||
| :---: | --- |
|
||||
| Discord | [Discord](https://discord.gg/YWrKVTn) |
|
||||
| Forum | [Linuserver.io forum][forumurl] |
|
||||
| IRC | freenode at `#linuxserver.io` more information at:- [IRC][ircurl]
|
||||
| Podcast | Covers everything to do with getting the most from your Linux Server plus a focus on all things Docker and containerisation! [Linuxserver.io Podcast][podcasturl] |
|
||||
|
||||
# [linuxserver/ci](huburl)
|
||||
|
||||
**This container is not meant for public consumption as it is hard coded to LinuxServer endpoints for storage of resulting reports**
|
||||
|
||||
The purpose of this container is to accept environment variables from our build system [linuxserver/pipeline-triggers](pipelineurl) to perform basic continuous integration on the software being built.
|
||||
|
||||
## Usage
|
||||
|
||||
The container can be run locally, but it is meant to be integrated into the LinuxServer build process:
|
||||
|
||||
```
|
||||
sudo docker run --rm -i \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-e IMAGE="linuxserver/<dockerimage>" \
|
||||
-e DELAY_START=<time in seconds> \
|
||||
-e TAGS="<single tag or array seperated by |>" \
|
||||
-e META_TAG=<manifest main dockerhub tag> \
|
||||
-e PORT=<port web application listens on internal docker port> \
|
||||
-e SSL=<true/false> \
|
||||
-e BASE=<alpine or debian based distro> \
|
||||
-e SECRET_KEY=<Digital Ocean spaces secret> \
|
||||
-e ACCESS_KEY=<Digital Ocean spaces key> \
|
||||
-e DOCKER_ENV="<optional, Array of env vars seperated by | IE test=test|test2=test2 or single var>" \
|
||||
-e WEB_AUTH="<optional, format user:passord>" \
|
||||
-e WEB_PATH="<optional, format /yourpath>" \
|
||||
-t linuxserver/ci:latest \
|
||||
python /ci/ci.py
|
||||
```
|
||||
|
||||
69
ci/ci.py
69
ci/ci.py
@ -26,7 +26,7 @@ global report_containers
|
||||
global report_status
|
||||
report_tests = []
|
||||
report_containers = []
|
||||
report_status = 'pass'
|
||||
report_status = 'PASS'
|
||||
|
||||
#############
|
||||
# Functions #
|
||||
@ -39,7 +39,43 @@ def core_fail(message):
|
||||
|
||||
# If any of the tests are marked failed do not push the resulting images
|
||||
def mark_fail():
|
||||
report_status = 'fail'
|
||||
report_status = 'FAIL'
|
||||
|
||||
# Remove container forcefully
|
||||
def remove_container(container):
|
||||
container.remove(force='true')
|
||||
|
||||
# Convert env input to dictionary
|
||||
def convert_env(vars):
|
||||
global dockerenv
|
||||
dockerenv = {}
|
||||
try:
|
||||
if '|' in vars:
|
||||
for varpair in vars.split('|'):
|
||||
var = varpair.split('=')
|
||||
dockerenv[var[0]] = var[1]
|
||||
else:
|
||||
var = vars.split('=')
|
||||
dockerenv[var[0]] = var[1]
|
||||
except Exception as error:
|
||||
core_fail(str(error))
|
||||
|
||||
# Set the optional parameters
|
||||
global webauth
|
||||
global webpath
|
||||
global dockerenv
|
||||
try:
|
||||
webauth = os.environ["WEB_AUTH"]
|
||||
except KeyError:
|
||||
webauth = 'user:password'
|
||||
try:
|
||||
webpath = os.environ["WEB_PATH"]
|
||||
except KeyError:
|
||||
webpath = ''
|
||||
try:
|
||||
convert_env(os.environ["DOCKER_ENV"])
|
||||
except KeyError:
|
||||
dockerenv = {}
|
||||
|
||||
# Make sure all needed env variables are set
|
||||
def check_env():
|
||||
@ -92,19 +128,16 @@ def take_screenshot(endpoint,container_tag):
|
||||
except TimeoutException as error:
|
||||
report_tests.append(['Screenshot ' + container_tag,'FAIL TIMEOUT'])
|
||||
mark_fail()
|
||||
|
||||
# Remove container forcefully
|
||||
def remove_container(container):
|
||||
container.remove(force='true')
|
||||
except WebDriverException as error:
|
||||
report_tests.append(['Screenshot ' + container_tag,'FAIL UNKNOWN'])
|
||||
mark_fail()
|
||||
|
||||
# Main container test logic
|
||||
def container_test(tag):
|
||||
# Start the container
|
||||
container = client.containers.run(image + ':' + tag, detach=True,
|
||||
environment={
|
||||
"APP_URL":"_",
|
||||
"DB_CONNECTION":"sqlite_testing"
|
||||
})
|
||||
container = client.containers.run(image + ':' + tag,
|
||||
detach=True,
|
||||
environment=dockerenv)
|
||||
# Watch the logs for no more than 2 minutes
|
||||
t_end = time.time() + 60 * 2
|
||||
logsfound = False
|
||||
@ -118,7 +151,6 @@ def container_test(tag):
|
||||
except Exception as error:
|
||||
print(error)
|
||||
remove_container(container)
|
||||
core_fail('Error getting container logs')
|
||||
if logsfound == True:
|
||||
report_tests.append(['Startup ' + tag,'PASS'])
|
||||
elif logsfound == False:
|
||||
@ -133,7 +165,7 @@ def container_test(tag):
|
||||
proto = 'http://'
|
||||
container.reload()
|
||||
ip = container.attrs["NetworkSettings"]["Networks"]["bridge"]["IPAddress"]
|
||||
take_screenshot(proto + ip + ':' + port ,tag)
|
||||
take_screenshot(proto + webauth + '@' + ip + ':' + port + webpath ,tag)
|
||||
# Dump package information
|
||||
if base == 'alpine':
|
||||
command = 'apk info -v'
|
||||
@ -147,11 +179,20 @@ def container_test(tag):
|
||||
print(error)
|
||||
report_tests.append(['Dump Versions ' + tag,'FAIL'])
|
||||
mark_fail()
|
||||
# Grab build version
|
||||
try:
|
||||
build_version = container.attrs["Config"]["Labels"]["build_version"]
|
||||
report_tests.append(['Get Build Version ' + tag,'PASS'])
|
||||
except Exception as error:
|
||||
build_version = 'ERROR'
|
||||
report_tests.append(['Get Build Version ' + tag,'FAIL'])
|
||||
mark_fail()
|
||||
# Add the info to the report
|
||||
report_containers.append({
|
||||
"tag":tag,
|
||||
"logs":logblob,
|
||||
"sysinfo":packages
|
||||
"sysinfo":packages,
|
||||
"build_version":build_version
|
||||
})
|
||||
#Cleanup
|
||||
remove_container(container)
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
| {{ test[0] }} | {{ test[1] }} |{% endfor %}
|
||||
{% for container in report_containers %}
|
||||
## {{ image }}:{{ container["tag"] }}
|
||||
### Build Version: {{ container["build_version"] }}
|
||||
|
||||
### Screenshot
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user