Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Drone support #1069

Merged
merged 14 commits into from
May 24, 2019
2 changes: 1 addition & 1 deletion conda_smithy/cli.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __init__(self, parser):
default="conda-forge",
help="github organisation under which to register this repo",
)
for ci in ["Azure", "Travis", "Circle", "Appveyor"]:
for ci in ["Azure", "Travis", "Circle", "Appveyor", "Drone"]:
scp.add_argument(
"--without-{}".format(ci.lower()),
dest=ci.lower(),
Expand Down
71 changes: 68 additions & 3 deletions conda_smithy/configure_feedstock.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import warnings
from collections import OrderedDict
import copy
import sys

import conda_build.api
import conda_build.utils
Expand Down Expand Up @@ -1002,7 +1003,6 @@ def render_appveyor(jinja_env, forge_config, forge_dir):


def _azure_specific_setup(jinja_env, forge_config, forge_dir, platform):
# TODO:
platform_templates = {
"linux": [
"azure-pipelines-linux.yml.tmpl",
Expand Down Expand Up @@ -1060,6 +1060,65 @@ def render_azure(jinja_env, forge_config, forge_dir):
)


def _drone_specific_setup(jinja_env, forge_config, forge_dir, platform):
# TODO Update to only use the build and setup script
platform_templates = {
"linux": [
"build_and_run.sh.tmpl",
],
"osx": [],
"win": [],
}
template_files = platform_templates.get(platform, [])

# Explicitly add in a newline character to ensure that jinja templating doesn't do something stupid
build_setup = "run_conda_forge_build_setup\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use _get_build_setup_line here?


if platform == "linux":
yum_build_setup = generate_yum_requirements(forge_dir)
if yum_build_setup:
forge_config['yum_build_setup'] = yum_build_setup

forge_config["build_setup"] = build_setup
forge_config["docker"]["interactive"] = False
jmreicha marked this conversation as resolved.
Show resolved Hide resolved

# Override the Docker image here so we don't need to set it in the template
forge_config["docker"]["image"] = "condaforge/linux-anvil-aarch64"
jmreicha marked this conversation as resolved.
Show resolved Hide resolved

_render_template_exe_files(
forge_config=forge_config,
target_dir=os.path.join(forge_dir, ".drone"),
jinja_env=jinja_env,
template_files=template_files,
)
forge_config["docker"]["interactive"] = True
jmreicha marked this conversation as resolved.
Show resolved Hide resolved


def render_drone(jinja_env, forge_config, forge_dir):
target_path = os.path.join(forge_dir, ".drone.yml")
template_filename = "drone.yml.tmpl"
fast_finish_text = ""

# TODO: for now just get this ignoring other pieces
platforms, archs, keep_noarchs, upload_packages = _get_platforms_of_provider(
"drone", forge_config
)

return _render_ci_provider(
"drone",
jinja_env=jinja_env,
forge_config=forge_config,
forge_dir=forge_dir,
platforms=platforms,
archs=archs,
fast_finish_text=fast_finish_text,
platform_target_path=target_path,
platform_template_file=template_filename,
platform_specific_setup=_drone_specific_setup,
keep_noarchs=keep_noarchs,
upload_packages=upload_packages,
)

def render_README(jinja_env, forge_config, forge_dir):
# we only care about the first metadata object for sake of readme
metas = conda_build.api.render(
Expand Down Expand Up @@ -1141,6 +1200,7 @@ def _load_forge_config(forge_dir, exclusive_config_file):
"interactive": True,
},
"templates": {},
"drone": {},
"travis": {},
"circle": {},
"appveyor": {},
Expand Down Expand Up @@ -1247,6 +1307,10 @@ def _load_forge_config(forge_dir, exclusive_config_file):
if config["provider"][platform] == "default":
config["provider"][platform] = "azure"

# TODO: Switch default to native builds using Drone
# if config["provider"]["linux_aarch64"] in {"native", "default"}:
# config["provider"]["linux_aarch64"] = "azure"

if config["provider"]["linux_ppc64le"] in {"native", "default"}:
config["provider"]["linux_ppc64le"] = "travis"

Expand Down Expand Up @@ -1375,7 +1439,7 @@ def main(
check_version_uptodate(r, "conda-smithy", __version__, True)
get_cfp_file_path(r, True)
return True

error_on_warn = False if no_check_uptodate else True
index = conda_build.conda_interface.get_index(channel_urls=["conda-forge"])
r = conda_build.conda_interface.Resolve(index)
Expand All @@ -1397,7 +1461,7 @@ def main(

config = _load_forge_config(forge_dir, exclusive_config_file)

for each_ci in ["travis", "circle", "appveyor"]:
for each_ci in ["travis", "circle", "appveyor", "drone"]:
if config[each_ci].pop("enabled", None):
warnings.warn(
"It is not allowed to set the `enabled` parameter for `%s`."
Expand All @@ -1423,6 +1487,7 @@ def main(
render_travis(env, config, forge_dir)
render_appveyor(env, config, forge_dir)
render_azure(env, config, forge_dir)
render_drone(env, config, forge_dir)
render_README(env, config, forge_dir)

if os.path.isdir(os.path.join(forge_dir, ".ci_support")):
Expand Down
10 changes: 10 additions & 0 deletions conda_smithy/templates/README.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ Current build status
</td>
</tr>
{%- endif -%}
{%- if drone.enabled -%}
<tr>
<td>Drone</td>
<td>
<a href="https://cloud.drone.io/{{ github.user_or_org }}/{{ github.repo_name }}">
<img alt="linux" src="{{ shield }}drone/build/{{ github.user_or_org }}/{{ github.branch_name }}.svg?label=Linux">
</a>
</td>
</tr>
{%- endif -%}
{%- if appveyor.enabled -%}
<tr>
<td>Appveyor</td>
Expand Down
70 changes: 70 additions & 0 deletions conda_smithy/templates/build_and_run.sh.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
jmreicha marked this conversation as resolved.
Show resolved Hide resolved

# Because this build is already running in a container we don't do the docker
# run. Likewise, the directories aren't volume mounted so we use the Drone values
# instead. Also note that environment variables are set in the .drone.yml file
# and passed into this script since docker run isn't used.

set -xeuo pipefail

# Activate the conda environment first
. /opt/conda/bin/activate

FEEDSTOCK_ROOT="${CI_WORKSPACE}"
RECIPE_ROOT="${FEEDSTOCK_ROOT}/recipe"
ARTIFACTS="${FEEDSTOCK_ROOT}/build_artifacts"

if [ -z "$CONFIG" ]; then
set +x
FILES=`ls .ci_support/linux_*`
CONFIGS=""
for file in $FILES; do
CONFIGS="${CONFIGS}'${file:12:-5}' or ";
done
echo "Need to set CONFIG env variable. Value can be one of ${CONFIGS:0:-4}"
exit 1
fi

mkdir -p "$ARTIFACTS"
DONE_CANARY="$ARTIFACTS/conda-forge-build-done-${CONFIG}"
rm -f "$DONE_CANARY"

# Conda build

#export PYTHONUNBUFFERED=1
#export FEEDSTOCK_ROOT=/home/conda/feedstock_root
#export RECIPE_ROOT=/home/conda/recipe_root
export CI_SUPPORT="${FEEDSTOCK_ROOT}/.ci_support"
export CONFIG_FILE="${CI_SUPPORT}/${CONFIG}.yaml"

cat >~/.condarc <<CONDARC

conda-build:
root-dir: /home/conda/feedstock_root/build_artifacts

CONDARC

conda install --yes --quiet conda-forge-ci-setup=2 conda-build -c conda-forge

# set up the condarc
setup_conda_rc "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}"

{% if build_setup -%}
{{ build_setup }}{% endif -%}
{% if yum_build_setup is defined -%}
{{ yum_build_setup }}{% endif -%}

# make the build number clobber
make_build_number "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}"

conda build "${RECIPE_ROOT}" -m "${CI_SUPPORT}/${CONFIG}.yaml" \
--clobber-file "${CI_SUPPORT}/clobber_${CONFIG}.yaml"

if [[ "${UPLOAD_PACKAGES}" != "False" ]]; then
upload_package "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}"
fi

touch "${ARTIFACTS}/conda-forge-build-done-${CONFIG}"
# verify that the end of the script was reached
test -f "$DONE_CANARY"
jmreicha marked this conversation as resolved.
Show resolved Hide resolved

27 changes: 27 additions & 0 deletions conda_smithy/templates/drone.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% if configs[0] -%}
{%- for config, platform, upload in configs | sort -%}
jmreicha marked this conversation as resolved.
Show resolved Hide resolved
---
kind: pipeline
name: {{ config }}

platform:
os: linux
arch: arm64

steps:
- name: Install and build
image: {{ docker.image }}
environment:
CONFIG: {{ config }}
UPLOAD_PACKAGES: {{ upload }}
PLATFORM: {{ platform }}
DOCKER_IMAGE: {{ docker.image }}
isuruf marked this conversation as resolved.
Show resolved Hide resolved
#BINSTAR_TOKEN: ""
commands:
{%- if 'linux' in platform %}
- ./.drone/build_and_run.sh
- echo "Done building"
{%- endif %}
{% endfor %}
{%- endif %}