Compare commits
5 Commits
780ccb4d51
...
173dc2d719
Author | SHA1 | Date |
---|---|---|
Ethan Paul | 173dc2d719 | |
Ethan Paul | 2cc57c32b7 | |
Ethan Paul | c9c34353fc | |
Ethan Paul | 0eb5b5e10e | |
Ethan Paul | 30200f082e |
|
@ -0,0 +1,47 @@
|
||||||
|
---
|
||||||
|
repos:
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
name: Fix whitespace at EOF
|
||||||
|
entry: end-of-file-fixer
|
||||||
|
language: system
|
||||||
|
types:
|
||||||
|
- text
|
||||||
|
|
||||||
|
- id: trailing-whitespace-fixer
|
||||||
|
name: Fix trailing line whitespace
|
||||||
|
entry: trailing-whitespace-fixer
|
||||||
|
language: system
|
||||||
|
types:
|
||||||
|
- text
|
||||||
|
|
||||||
|
- id: black
|
||||||
|
name: Enforce python formatting
|
||||||
|
entry: black
|
||||||
|
language: system
|
||||||
|
types:
|
||||||
|
- python
|
||||||
|
|
||||||
|
- id: check-toml
|
||||||
|
name: Check TOML file syntax
|
||||||
|
entry: check-toml
|
||||||
|
language: system
|
||||||
|
types:
|
||||||
|
- toml
|
||||||
|
|
||||||
|
- id: check-yaml
|
||||||
|
name: Check YAML file syntax
|
||||||
|
entry: check-yaml
|
||||||
|
language: system
|
||||||
|
args:
|
||||||
|
- "--unsafe"
|
||||||
|
types:
|
||||||
|
- yaml
|
||||||
|
|
||||||
|
- id: check-merge-conflict
|
||||||
|
name: Check for unresolved git conflicts
|
||||||
|
entry: check-merge-conflict
|
||||||
|
language: system
|
||||||
|
types:
|
||||||
|
- text
|
|
@ -0,0 +1,61 @@
|
||||||
|
# Build container
|
||||||
|
# =================================
|
||||||
|
FROM python:3.11 AS build
|
||||||
|
|
||||||
|
RUN python -m pip install pip --upgrade
|
||||||
|
RUN curl -sSL -o /install-poetry.py https://install.python-poetry.org
|
||||||
|
RUN python /install-poetry.py --yes
|
||||||
|
|
||||||
|
ADD . /build
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
RUN /root/.local/bin/poetry self add poetry-plugin-export
|
||||||
|
RUN /root/.local/bin/poetry export \
|
||||||
|
--format requirements.txt \
|
||||||
|
--output /build/requirements.txt \
|
||||||
|
--without-hashes
|
||||||
|
RUN python -m pip wheel \
|
||||||
|
--wheel-dir /build/wheels \
|
||||||
|
--requirement /build/requirements.txt \
|
||||||
|
--disable-pip-version-check \
|
||||||
|
--no-cache-dir
|
||||||
|
|
||||||
|
|
||||||
|
# Runtime container
|
||||||
|
# ==================================
|
||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
ARG OPENTOFU_VERSION
|
||||||
|
ARG SEMAPHORE_VERSION
|
||||||
|
|
||||||
|
ENV SEMAPHORE_RUNNER_CONFIG_FILE /semaphore/config.json
|
||||||
|
|
||||||
|
COPY --from=build /build/wheels /tmp/wheels
|
||||||
|
|
||||||
|
RUN apt-get update --yes && \
|
||||||
|
apt-get install --yes \
|
||||||
|
openssh-client \
|
||||||
|
apt-transport-https \
|
||||||
|
ca-certificates \
|
||||||
|
curl \
|
||||||
|
gnupg && \
|
||||||
|
mkdir --parents /tmp/apt && \
|
||||||
|
curl -sSL -o /tmp/apt/opentofu.deb https://github.com/opentofu/opentofu/releases/download/v${OPENTOFU_VERSION}/tofu_${OPENTOFU_VERSION}_amd64.deb && \
|
||||||
|
curl -sSL -o /tmp/apt/semaphore.deb https://github.com/ansible-semaphore/semaphore/releases/download/v${SEMAPHORE_VERSION}/semaphore_${SEMAPHORE_VERSION}_linux_amd64.deb && \
|
||||||
|
apt-get install --yes /tmp/apt/*.deb && \
|
||||||
|
apt-get clean --yes && \
|
||||||
|
rm -rf /tmp/apt && \
|
||||||
|
python -m pip install /tmp/wheels/*.whl \
|
||||||
|
--upgrade \
|
||||||
|
--pre \
|
||||||
|
--no-index \
|
||||||
|
--no-cache-dir \
|
||||||
|
--find-links /tmp/wheels \
|
||||||
|
--disable-pip-version-check && \
|
||||||
|
rm -rf /tmp/wheels && \
|
||||||
|
mkdir --parents /semaphore
|
||||||
|
|
||||||
|
ADD entrypoint.sh /entrypoint.sh
|
||||||
|
ADD configure.py /configure.py
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
@ -0,0 +1,17 @@
|
||||||
|
REPOSITORY = vcs.enp.one/skylab/semaphore-runner
|
||||||
|
OPENTOFU_VERSION = 1.6.2
|
||||||
|
SEMAPHORE_VERSION = 2.9.45
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: help docs
|
||||||
|
# source: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
||||||
|
help: ## List Makefile targets
|
||||||
|
$(info Makefile documentation)
|
||||||
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
|
|
||||||
|
image: ## Build image
|
||||||
|
podman build . --tag $(REPOSITORY):$(SEMAPHORE_VERSION) --build-arg "OPENTOFU_VERSION=$(OPENTOFU_VERSION)" --build-arg "SEMAPHORE_VERSION=$(SEMAPHORE_VERSION)"
|
||||||
|
|
||||||
|
push: image ## Build and publish image
|
||||||
|
podman push $(REPOSITORY):$(SEMAPHORE_VERSION)
|
|
@ -0,0 +1,31 @@
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
CONSTRUCTED_CONFIG_FILE = "/tmp/runner-config.json"
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> str:
|
||||||
|
try:
|
||||||
|
config = {
|
||||||
|
"registration_token": os.environ["SEMAPHORE_RUNNER_REGISTRATION_TOKEN"],
|
||||||
|
"config_file": os.getenv(
|
||||||
|
"SEMAPHORE_RUNNER_CONFIG_FILE", "/semaphore/runner.json"
|
||||||
|
),
|
||||||
|
"api_url": os.environ["SEMAPHORE_RUNNER_API_URL"],
|
||||||
|
"max_parallel_tasks": int(
|
||||||
|
os.getenv("SEMAPHORE_RUNNER_MAX_PARALLEL_TASKS", "1")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
except KeyError as err:
|
||||||
|
print(f"Missing required configuration value {err}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
with open(CONSTRUCTED_CONFIG_FILE, "w") as outfile:
|
||||||
|
json.dump(config, outfile, indent=4)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
python /configure.py
|
||||||
|
|
||||||
|
semaphore runner --config=/tmp/runner-config.json
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
||||||
|
[tool.poetry]
|
||||||
|
name = "semaphore-runner"
|
||||||
|
package-mode = false
|
||||||
|
description = "Custom runner for semaphore"
|
||||||
|
authors = ["Ethan Paul <admin@enp.one>"]
|
||||||
|
license = "MIT"
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.11"
|
||||||
|
ansible-core = "^2.16.4"
|
||||||
|
docker = "^7.0.0"
|
||||||
|
paramiko = "^3.4.0"
|
||||||
|
poetry = "^1.8.1"
|
||||||
|
poetry-plugin-export = "^1.6.0"
|
||||||
|
|
||||||
|
|
||||||
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
black = "^24.2.0"
|
||||||
|
reorder-python-imports = "^3.12.0"
|
||||||
|
pylint = "^3.1.0"
|
||||||
|
pre-commit = "^3.6.2"
|
||||||
|
pre-commit-hooks = "^4.5.0"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
Loading…
Reference in New Issue