-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
184 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Build Meshtastic build container | ||
on: | ||
push: | ||
# build and push anytime commits are pushed/merged | ||
branches: | ||
- main | ||
release: | ||
# build and push upon release creation | ||
types: | ||
- created | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build_and_push_latest: | ||
runs-on: ubuntu-24.04 | ||
name: Build and push upon merge | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
attestations: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: docker/setup-qemu-action@v3 | ||
|
||
- uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker Login GHCR | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
# platforms: linux/amd64,linux/arm64 | ||
platforms: linux/amd64 | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
FROM python:3.12-bookworm | ||
ENV PIP_ROOT_USER_ACTION=ignore | ||
|
||
# Add build scripts to PATH | ||
RUN git clone --no-checkout --depth 1 https://github.com/meshtastic/firmware.git /meshtastic && \ | ||
git -C /meshtastic config core.sparseCheckout true && \ | ||
echo "bin/*" > /meshtastic/.git/info/sparse-checkout && \ | ||
git -C /meshtastic checkout master | ||
ENV PATH="/meshtastic/bin:$PATH" | ||
# Add build scripts (firmware/bin) to PATH | ||
# RUN git clone --no-checkout --depth 1 https://github.com/meshtastic/firmware.git /meshtastic && \ | ||
# git -C /meshtastic config core.sparseCheckout true && \ | ||
# echo "bin/*" > /meshtastic/.git/info/sparse-checkout && \ | ||
# git -C /meshtastic checkout master | ||
# ENV PATH="/meshtastic/bin:$PATH" | ||
|
||
# Install build dependencies | ||
RUN apt update && apt install -y \ | ||
build-essential \ | ||
cppcheck libbluetooth-dev libgpiod-dev libyaml-cpp-dev && \ | ||
# Install DRA (GitHub Releases downloader) | ||
wget 'https://github.com/devmatteini/dra/releases/download/0.6.2/dra_0.6.2-1_amd64.deb' && \ | ||
dpkg --install dra_0.6.2-1_amd64.deb && rm dra_0.6.2-1_amd64.deb && \ | ||
# wget 'https://github.com/devmatteini/dra/releases/download/0.6.2/dra_0.6.2-1_amd64.deb' && \ | ||
# dpkg --install dra_0.6.2-1_amd64.deb && rm dra_0.6.2-1_amd64.deb && \ | ||
apt clean && rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Python dependencies | ||
RUN python -m pip install --upgrade pip && \ | ||
pip install -U --no-build-isolation --no-cache-dir "setuptools<72" && \ | ||
pip install -U --no-build-isolation GitPython && \ | ||
pip install -U platformio adafruit-nrfutil --no-build-isolation && \ | ||
pip install -U poetry --no-build-isolation && \ | ||
pip install -U meshtastic --pre --no-build-isolation | ||
|
||
# Upgrade PlatformIO | ||
RUN pio upgrade | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT [ "/entrypoint.sh" ] | ||
# COPY entrypoint.sh /entrypoint.sh | ||
# ENTRYPOINT [ "/entrypoint.sh" ] | ||
|
||
COPY entrypoint.py /entrypoint.py | ||
ENTRYPOINT [ "/entrypoint.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
import requests | ||
import tarfile | ||
import sys | ||
import GitPython | ||
|
||
inputs = { | ||
'arch': os.getenv('INPUT_ARCH'), | ||
'board': os.getenv('INPUT_BOARD'), | ||
'build-script-path': os.getenv('INPUT_BUILD-SCRIPT-PATH'), | ||
'remove-debug-flags': str(os.getenv('INPUT_REMOVE-DEBUG-FLAGS', '')).split(), | ||
'ota-firmware-source': os.getenv('INPUT_OTA-FIRMWARE-SOURCE', ''), | ||
'ota-firmware-target': os.getenv('INPUT_OTA-FIRMWARE-TARGET', ''), | ||
'include-web-ui': bool(os.getenv('INPUT_INCLUDE-WEB-UI', False)) | ||
} | ||
|
||
env = { | ||
'GITHUB_ACTIONS': bool(os.getenv('GITHUB_ACTIONS')), | ||
'PLATFORMIO_CACHE_DIR': os.getenv('PLATFORMIO_CACHE_DIR'), | ||
'PIP_DOWNLOAD_CACHE': os.getenv('PIP_DOWNLOAD_CACHE') | ||
} | ||
|
||
def gh_latest_release(owner, repo): | ||
r = requests.get(f"https://api.github.com/repos/{owner}/{repo}/releases/latest") | ||
r_j = r.json() | ||
if r.status_code == 200: | ||
return r_j | ||
else: | ||
raise Exception(f"Failed to fetch latest release from {owner}/{repo}") | ||
|
||
def download_file(url, dest): | ||
print(f"Downloading {url} to {dest}") | ||
r = requests.get(url, stream=True) | ||
with open(dest, 'wb') as f: | ||
for chunk in r.iter_content(chunk_size=8192): | ||
f.write(chunk) | ||
|
||
def extract_tar(tar_file, extract_to, remove_src=False): | ||
print(f"Extracting {tar_file} to {extract_to}") | ||
with tarfile.open(tar_file, 'r') as tar: | ||
tar.extractall(extract_to) | ||
if remove_src == True: | ||
print(f"..Cleaning up {tar_file}") | ||
os.remove(tar_file) | ||
|
||
# ============== | ||
|
||
# Workaround for the "safe.directory" issue | ||
os.system("git config --system --add safe.directory /github/workspace") | ||
|
||
# Web UI | ||
if inputs['include-web-ui'] == True: | ||
mt_web = gh_latest_release('meshtastic', 'web') | ||
for asset in mt_web['assets']: | ||
if asset['name'] == 'build.tar': | ||
# Download build.tar | ||
download_file(asset['browser_download_url'], 'build.tar') | ||
# Extract build.tar | ||
extract_tar('build.tar','data/static', remove_src=True) | ||
|
||
# Remove debug flags for release | ||
if len(inputs['remove-debug-flags']) > 0: | ||
for flag in inputs['remove-debug-flags']: | ||
os.system(f"sed -i /DDEBUG_HEAP/d {flag}") | ||
|
||
# Run the Build | ||
r_build = subprocess.run([inputs['build-script-path'], inputs['board']], check=True) | ||
|
||
# Pull OTA firmware | ||
if inputs['ota-firmware-source'] != '' and inputs['ota-firmware-target'] != '': | ||
ota_fw = gh_latest_release('meshtastic', 'firmware-ota') | ||
for asset in ota_fw['assets']: | ||
if asset['name'] == inputs['ota-firmware-source']: | ||
# Download firmware.bin | ||
download_file(asset['browser_download_url'], inputs['ota-firmware-target']) | ||
|
||
# When running in GitHub Actions | ||
if env['GITHUB_ACTIONS']: | ||
# Hack! - Add checked-out firmware/bin to the python module path | ||
cwd_bin = os.path.join(os.getcwd(), 'bin') | ||
sys.path.append(cwd_bin) | ||
from readprops import readProps # type: ignore | ||
# /Hack! | ||
|
||
# Get release version string | ||
verObj = readProps("version.properties") | ||
version_str = verObj['long'] | ||
# Write version string to GitHub Actions output | ||
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | ||
print(f'version={version_str}', file=fh) | ||
|
||
# Fix cache permissions | ||
os.system(f'chmod -R 777 {env['PLATFORMIO_CACHE_DIR']}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters