Skip to content

Commit

Permalink
Add container-build tool
Browse files Browse the repository at this point in the history
  • Loading branch information
wwahammy committed Dec 1, 2024
1 parent a2094c7 commit 5cbc09e
Show file tree
Hide file tree
Showing 6 changed files with 2,040 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/container-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and test on containers

on:
workflow_dispatch:
push:

jobs:
build_and_test:
strategy:
matrix:
os: [ubuntu-latest]
builder: ["podman"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Update podman
run: |
# from https://askubuntu.com/questions/1414446/whats-the-recommended-way-of-installing-podman-4-in-ubuntu-22-04
ubuntu_version='22.04'
key_url="https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_${ubuntu_version}/Release.key"
sources_url="https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_${ubuntu_version}"
echo "deb $sources_url/ /" | sudo tee /etc/apt/sources.list.d/devel-kubic-libcontainers-unstable.list
curl -fsSL $key_url | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/devel_kubic_libcontainers_unstable.gpg > /dev/null
sudo apt update
sudo apt install -y podman
- uses: actions/checkout@v4
- name: Make on Unix
run: ./container-build.py make -d fast

20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM docker.io/ubuntu:20.04
RUN apt-get -qq update && \
DEBIAN_FRONTEND=noninteractive apt-get -qq install -y build-essential libcap-dev xz-utils zip \
unzip strace curl discount git python3 zlib1g-dev \
cmake flex bison locales clang && \
rm -rf /var/lib/apt/lists/*
COPY --from=docker.io/golang:1.21 /usr/local/go /usr/local/go
ENV PATH "$PATH:/usr/local/go/bin"
RUN groupadd -g 1000 file-builder
RUN useradd -m -g 1000 -u 1000 file-builder
RUN chown -R file-builder:file-builder /usr/local
USER file-builder
RUN curl https://install.meteor.com/?release=2.3.5 | sh
USER root
RUN chown -R root:root /usr/local
USER file-builder
ENV PATH $PATH:/home/file-builder/.meteor
ENV METEOR_WAREHOUSE_DIR /home/file-builder/.meteor
ENV USER file-builder
WORKDIR /sandstorm
73 changes: 73 additions & 0 deletions container-build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/python
import argparse, shlex, subprocess, os, getpass

# from https://stackoverflow.com/a/4760274/259046
def runProcess(exe):
p = subprocess.run(shlex.split(exe), stderr=subprocess.STDOUT)
while(True):
if not isinstance(p, subprocess.CompletedProcess):
retcode = p.poll()
else:
retcode = p.returncode

stdout = p.stdout
print(stdout)
if retcode is not None:
if retcode != 0:
exit(retcode)
else:
break




parser = argparse.ArgumentParser(description='Build Sandstorm using an Ubuntu 20.04 Docker/OCI container')
parser.add_argument("action", choices=["make", "prepare", "shell"], default="make", nargs="?")
parser.add_argument('--container-builder', dest="container_builder", default='podman', help='Command you run for building container from command line')
parser.add_argument('--container-runner', dest="container_runner", default='podman', help='Command you run for running container from command line')
parser.add_argument('args', nargs=argparse.REMAINDER)

args = parser.parse_args()

def prepare():
script ="{builder_cmd} build . -t sandstorm-build".format(builder_cmd=args.container_builder)
print(script)
runProcess(script)

def prepare_cmd(command):
return "{runner_cmd} run --rm -ti \
-v {pwd}:/sandstorm \
-v {pwd}/scripts/podman-entrypoint.sh:/podman-entrypoint.sh \
--userns=keep-id:uid=1000,gid=1000 \
--entrypoint=/podman-entrypoint.sh \
--cap-add=SYS_PTRACE sandstorm-build {command} {args}".format(
runner_cmd=args.container_runner,
pwd=os.getcwd(),
command=command,
args=' '.join(args.args)
)

#

def make():
script = prepare_cmd("make")
print(script)
runProcess(script)

def shell():
script = prepare_cmd("bash")
print(script)
runProcess(script)

prepare()

if (args.action == "make"):
make()

if (args.action == "shell"):
shell()





4 changes: 3 additions & 1 deletion find-meteor-dev-bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ TOOLDIR=$(echo $TOOL_VERSION | tr @ /)

echo " $TOOL_VERSION" >&2

readlink -f $METEOR_WAREHOUSE_DIR/packages/$TOOLDIR/mt-os.linux.x86_64/dev_bundle > "$CACHE_FILE"
echo -n "$TOOLDIR" >&2
echo -n "$METEOR_WAREHOUSE_DIR/packages/$TOOLDIR/mt-os.linux.x86_64/dev_bundle" >&2
echo "$METEOR_WAREHOUSE_DIR/packages/$TOOLDIR/mt-os.linux.x86_64/dev_bundle" > "$CACHE_FILE"
cat "$CACHE_FILE"
Loading

0 comments on commit 5cbc09e

Please sign in to comment.