Skip to content

Commit

Permalink
Make repository usable in GitHub Action (#147)
Browse files Browse the repository at this point in the history
* Make repository usable in GitHub Action

* let's try something else

* quote

* drop it

* go back

* fix copy

* Fix syntax

* add quemu

* sudo

* fix missing

* remove setup

* add test

* limit pip

* use variable

* add elf back
  • Loading branch information
ludeeus authored Jan 8, 2021
1 parent 8ed7a73 commit 8703033
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WORKDIR /workspace

# Install Python dependencies from requirements.txt if it exists
COPY requirements.txt requirements_tests.txt /workspace/
RUN pip install -r requirements.txt \
RUN pip install pip==20.2 \
&& pip install -r requirements.txt \
&& pip3 install -r requirements_tests.txt \
&& pip install tox
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ COPY requirements.txt /usr/src/
RUN apk add --no-cache \
rsync \
openssh-client \
&& pip3 install --no-cache-dir --find-links \
"https://wheels.home-assistant.io/alpine-$(cut -d '.' -f 1-2 < /etc/alpine-release)/${BUILD_ARCH}/" \
pip==20.2 \
&& pip3 install --no-cache-dir --find-links \
"https://wheels.home-assistant.io/alpine-$(cut -d '.' -f 1-2 < /etc/alpine-release)/${BUILD_ARCH}/" \
-r /usr/src/requirements.txt \
Expand Down
175 changes: 175 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: "Home Assistant wheels builder"
description: "Builds and publishes python wheels"
inputs:
tag:
description: "The tag for the builder that should be used"
default: "dev"
arch:
description: "Build architecture"
required: true
apk:
description: "apk packages that should be installed"
default: "build-base"
pip:
description: "pip packages that should be installed"
default: "Cython"
path:
description: "The path to be used for the builder"
default: ""
env-file:
description: "Set to true if the builder should use a env file"
default: false
requirements:
description: "The requirements file"
default: ""
requirements-diff:
description: "The requirements diff file"
default: ""
constraints:
description: "The constraints file"
default: ""
local:
description: "Set to true if not uploading wheels"
default: false
test:
description: "Set to true if local"
default: false
single:
description: "Set to true if should build each wheel as a single prosess"
default: false
name:
description: "Job name"
default: "Wheels"
skip-binary:
description: "Skip binaries"
default: ""
audit:
description: "Audit wheels"
default: false
wheels-key:
description: "SSH keys for the wheels host"
required: true
wheels-host:
description: "SSH keys for the wheels host"
required: true
wheels-user:
description: "User for wheels host"
default: "wheels"
wheels-index:
description: "The wheels index URL"
default: "https://wheels.home-assistant.io"

runs:
using: "composite"
steps:
- shell: bash
run: |
mkdir -p .ssh
echo -e "-----BEGIN RSA PRIVATE KEY-----\n${{ inputs.wheels-key }}\n-----END RSA PRIVATE KEY-----" >> .ssh/id_rsa
#ssh-keyscan -H ${{ inputs.wheels-host }} >> .ssh/known_hosts
chmod 600 .ssh/*
- shell: bash
id: pull
run: |
name="homeassistant/${{ inputs.arch }}-base-python:${{ inputs.tag }}"
docker pull "$name"
echo "::set-output name=name::$name"
- shell: bash
id: options
run: |
declare -a build
declare -a docker
# Data Path
if [ -n "${{ inputs.path }}" ]; then
data_path="${{ github.workspace }}/${{ inputs.path }}"
else
data_path="${{ github.workspace }}"
fi
# Environment
if [ "${{ inputs.env-file }}" == "True" ] && [ -f .env_file ]; then
docker+=("--env-file .env_file")
fi
if [ -f "${{ inputs.requirements }}" ]; then
build+=("--requirement ${{ inputs.requirements }}")
fi
if [ -f "${{ inputs.requirements-diff }}" ]; then
build+=("--requirement-diff ${{ inputs.requirements-diff }}")
fi
if [ -f "${{ inputs.constraints }}" ]; then
build+=("--constraint ${{ inputs.constraints }}")
fi
if [ -d "${{ inputs.prebuild-dir }}" ]; then
build+=("--prebuild-dir ${{ inputs.prebuild-dir }}")
fi
if [ "${{ inputs.single }}" == "True" ]; then
build+=("--single")
fi
if [ "${{ inputs.local }}" == "True" ]; then
build+=("--local")
fi
if [ "${{ inputs.audit }}" == "True" ]; then
build+=("--auditwheel")
fi
if [ -n "${{ inputs.skip-binary }}" ]; then
build+=("--skip-binary ${{ inputs.skip-binary }}")
fi
echo "::set-output name=build::${build[@]}"
echo "::set-output name=docker::${docker[@]}"
echo "::set-output name=path::$data_path"
- shell: bash
run: |
sudo apt-get update --fix-missing
sudo apt-get install -y qemu binfmt-support qemu-user-static
- shell: bash
run: |
echo "Build image"
docker build ${{ github.action_path }} \
-t wheels-builder \
--build-arg BUILD_FROM=${{ steps.pull.outputs.name }} \
--build-arg BUILD_ARCH=${{ inputs.arch }}
- shell: bash
run: |
echo "Create container"
docker create --name "${{ inputs.name }}" -t \
--workdir /data \
${{ steps.options.outputs.docker }} \
"wheels-builder" \
--apk "${{ inputs.apk }}" \
--pip "${{ inputs.pip }}" \
--index "${{ inputs.wheels-index }}" \
--upload rsync \
--remote "{{ inputs.wheels-user }}@${{ inputs.wheels-host }}:/opt/wheels" \
${{ steps.options.outputs.build }}
- shell: bash
run: |
echo "Copy repository and SSH files to the container"
docker cp "${{ steps.options.outputs.path }}/." "${{ inputs.name }}:/data"
#docker cp -a .ssh/ "${{ inputs.name }}:/root/.ssh"
- shell: bash
id: build
run: |
for i in {1..3}; do
echo "$i attempt on starting the container"
docker start -a "${{ inputs.name }}"
return_val=$?
if [ ${return_val} -ne 0 ] && [ ${return_val} -ne 109 ] && [ ${return_val} -ne 80 ]; then
continue
fi
break
done
echo "::set-output name=return_val::$return_val"
- shell: bash
run: |
docker rm -f "${{ inputs.name }}"
exit ${{ steps.build.outputs.return_val }}
2 changes: 2 additions & 0 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pr:
variables:
- name: versionHadolint
value: "v1.16.3"
- name: VIRTUALENV_PIP
value: "20.2"

jobs:
- job: "Tox"
Expand Down
7 changes: 6 additions & 1 deletion builder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
@click.option(
"--local", is_flag=True, default=False, help="Build wheel from local folder setup."
)
@click.option(
"--test", is_flag=True, default=False, help="Test building wheels, no upload."
)
@click.option("--upload", default="rsync", help="Upload plugin to upload wheels.")
@click.option(
"--remote", required=True, type=str, help="Remote URL pass to upload plugin."
Expand All @@ -89,6 +92,7 @@ def builder(
single: bool,
auditwheel: bool,
local: bool,
test: bool,
upload: str,
remote: str,
timeout: int,
Expand Down Expand Up @@ -161,7 +165,8 @@ def builder(
run_auditwheel(wheels_dir)

fix_wheels_name(wheels_dir)
run_upload(upload, output, remote)
if not test:
run_upload(upload, output, remote)

sys.exit(exit_code)

Expand Down
2 changes: 1 addition & 1 deletion builder/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ def install_pips(index: str, pips: str) -> None:
packages = " ".join(pips.split(";"))

run_command(
f"pip install --progress-bar off --upgrade --no-cache-dir --prefer-binary --find-links {index} {packages}",
f"pip install --disable-pip-version-check --progress-bar off --upgrade --no-cache-dir --prefer-binary --find-links {index} {packages}",
)

0 comments on commit 8703033

Please sign in to comment.