Commit a7b6fbf2 authored by José Henrique's avatar José Henrique
Browse files

Initial commit

parents
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
before_script:
- pip3 install --upgrade -r requirements.txt
variables:
PYTHONUNBUFFERED: 1
build:
tags:
- buildserver
stage: build
script:
- python build.py
only:
- triggers
- web
- api
{
"python.pythonPath": "/usr/bin/python3",
"python.linting.pylintEnabled": false,
"python.linting.enabled": true,
"python.linting.pycodestyleEnabled": true,
"python.formatting.provider": "autopep8"
}
\ No newline at end of file
#!/usr/bin/env python3
import time
import sys
import os
from build_env import build_env_vars
from docker_utils import start_notifier, start_build
notifier_env_vars = build_env_vars
notifier_env_vars["TELEGRAM_TOKEN"] = os.getenv("TELEGRAM_TOKEN")
notifier_env_vars["TELEGRAM_CHAT_ID"] = os.getenv("TELEGRAM_CHAT_ID")
if __name__ == "__main__":
start_notifier(notifier_env_vars)
if start_build(build_env_vars):
print("Build success.\n")
else:
print("Build failed.\n")
sys.exit(1)
import os
import sys
import socket
def default_value(key, def_value):
if key not in build_env_vars:
print("'" + key + "' not defined, " +
"using '" + def_value + "' as default")
build_env_vars[key] = def_value
build_env_vars = {}
for k in ["device", "version", "production", "eng_build",
"wip_branch", "generate_incremental", "repopick",
"CI_RUNNER_DESCRIPTION", "CI_JOB_URL", "CI_PIPELINE_ID"]:
if os.getenv(k):
build_env_vars[k] = os.getenv(k)
if "device" not in build_env_vars:
sys.exit("Device not specified")
default_value("version", "ten")
default_value("production", "false")
default_value("eng_build", "false")
default_value("wip_branch", "false")
default_value("generate_incremental", "false")
default_value("CI_RUNNER_DESCRIPTION", socket.gethostname())
manifest_url_main = "https://github.com/PixelExperience/manifest"
if build_env_vars["version"] == "ten":
build_env_vars["manifest_url"] = manifest_url_main
build_env_vars["manifest_branch"] = "ten"
build_env_vars["fallback_branch"] = build_env_vars["manifest_branch"]
elif build_env_vars["version"] == "ten_plus":
build_env_vars["manifest_url"] = manifest_url_main
build_env_vars["manifest_branch"] = "ten-plus"
build_env_vars["fallback_branch"] = "ten"
else:
sys.exit("Invalid version")
# Build types
build_env_vars["production"] = build_env_vars["production"] == "true"
build_env_vars["eng_build"] = (build_env_vars["production"] is False
and build_env_vars["eng_build"] == "true")
build_env_vars["wip_branch"] = (build_env_vars["production"] is False
and build_env_vars["wip_branch"] == "true")
# Incremental
build_env_vars["generate_incremental"] = (
build_env_vars["generate_incremental"] == "true")
# Working dir
build_env_vars["working_dir"] = "/mnt/roms/pe_" + build_env_vars["version"]
# Extras
build_env_vars["runner_name"] = build_env_vars["CI_RUNNER_DESCRIPTION"]
#!/usr/bin/env python3
import docker
import os
import traceback
import threading
import time
docker_client = docker.from_env()
def stream_container_logs_thread(container_name):
time.sleep(1)
try:
container = docker_client.containers.get(container_name)
for line in container.logs(stream=True):
print(line.strip().decode("utf-8"))
except docker.errors.NotFound:
pass
def stream_container_logs(container_name):
threading.Thread(target=stream_container_logs_thread,
args=(container_name,)).start()
def kill_container(container_name):
try:
docker_client.containers.get(container_name).remove(force=True)
print("Killing old container: " + container_name)
except Exception:
pass
def pull_image(image_name):
print("Pulling image: " + image_name)
docker_client.images.pull(image_name)
def sanitize_environment_vars(environment_vars):
for k, v in environment_vars.items():
if type(v) == bool:
environment_vars[k] = str(v).lower()
return environment_vars
def start_notifier(environment_vars):
environment_vars = sanitize_environment_vars(environment_vars)
container_name = "android_build_notifier"
image_name = "pixelexperience/android_build_notifier_ci"
volumes_to_mount = {
"/var/run/docker.sock": {
"bind": "/var/run/docker.sock", "mode": "rw"
}
}
kill_container(container_name)
pull_image(image_name)
print("Starting container: " + container_name)
docker_client.containers.run(image_name,
detach=True,
remove=True,
name=container_name,
volumes=volumes_to_mount,
environment=environment_vars)
def start_build(environment_vars):
environment_vars = sanitize_environment_vars(environment_vars)
container_name = "android_build"
image_name = "pixelexperience/android_build_ci"
volumes_to_mount = {
"/mnt/roms": {
"bind": "/roms", "mode": "rw"
},
"/home/gitlab-runner/.gitcookies": {
"bind": "/home/android_build/.gitcookies", "mode": "ro"
}
}
kill_container(container_name)
pull_image(image_name)
print("Starting container: " + container_name)
try:
stream_container_logs(container_name)
docker_client.containers.run(image_name,
remove=True,
name=container_name,
volumes=volumes_to_mount,
environment=environment_vars)
return True
except docker.errors.ContainerError:
return False
except Exception:
traceback.print_exc()
return False
docker
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment