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

Add support for building in a container #3722

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
[push, pull_request, workflow_dispatch]

jobs:
build_and_test:
strategy:
matrix:
os: [ubuntu-22.04, 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
if: ${{ matrix.os == 'ubuntu-22.04' }}
- 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
67 changes: 67 additions & 0 deletions container-build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/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='Setup and use a Sandstorm Docker/OCI build container.')
parser.add_argument("action", choices=["make", "prepare", "shell"], default="make", nargs="?", help='')
parser.add_argument('--container-builder', dest="container_builder", default='podman', help='Command you run for building container from command line (Default: %(default))')
parser.add_argument('--container-runner', dest="container_runner", default='podman', help='Command you run for running container from command line (Default: %(default))')
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 format_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 = format_cmd("make")
print(script)
runProcess(script)

def shell():
script = format_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"
5 changes: 5 additions & 0 deletions scripts/podman-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

"$@"
Loading