diff --git a/.dockerfile b/.dockerfile new file mode 100644 index 0000000..b3174e9 --- /dev/null +++ b/.dockerfile @@ -0,0 +1,6 @@ +# TODO: use alpine when available +FROM debian:12-slim +ADD artifacts.tar.gz /install +RUN dpkg -i /install/artifacts/sci_*-1_amd64.deb +RUN rm -rf /install +ENTRYPOINT ["sci"] diff --git a/.sci.sh b/.sci.sh new file mode 100755 index 0000000..a358d9a --- /dev/null +++ b/.sci.sh @@ -0,0 +1,59 @@ +#!/bin/sh +set -e +echo ">>> checking if required environment is set..." +test -n "$DOCKER_TOKEN" + +echo ">>> compiling..." +make +export VERSION=$(./out/bin/sci -V) + +echo ">>> building source dist..." +make dist +SRC_SHA256=$(sha256sum "sci-${VERSION}.tar.gz" | awk '{ print $1 }') +sed "s/SRC_SHA256/${SRC_SHA256}/g" < PKGBUILD.in > PKGBUILD + +# arch +echo ">>> building archbuilder image..." +docker build -t archbuilder -f arch-builder.dockerfile . + +echo ">>> building arch package in archbuilder docker image..." +docker run --rm -it -v .:/src -e VERSION archbuilder sh -c '\ + cd && \ + cp /src/sci-$VERSION.tar.gz /src/PKGBUILD . && \ + makepkg && \ + cp *.zst /src +' + +# debian +echo ">>> building debbuilder image..." +docker build -t debbuilder -f deb-builder.dockerfile . + +echo ">>> building .deb in debbuilder docker image..." +docker run --rm -it -v .:/src -e VERSION debbuilder sh -c '\ + cd && \ + mkdir -p artifacts && \ + cp /src/sci-$VERSION.tar.gz . && \ + mv sci-$VERSION.tar.gz sci_$VERSION.orig.tar.gz && \ + tar xf sci_$VERSION.orig.tar.gz && \ + cd sci-$VERSION && \ + cp -r /src/debian . && \ + debuild && \ + cp ../*.deb ~/artifacts && \ + cp ../*.dsc ~/artifacts && \ + cp ../*.build ~/artifacts && \ + cp ../*.buildinfo ~/artifacts && \ + cp ../*.changes ~/artifacts && \ + cp ../*.tar.xz ~/artifacts && \ + cp ../*.tar.gz ~/artifacts && \ + cd && \ + tar czf /src/artifacts.tar.gz artifacts +' + +echo ">>> building sci docker image..." +export OWNER="git.gtz.dk/agj" +docker build -t ${OWNER}/sci:${VERSION} -t ${OWNER}/sci:latest -f .dockerfile . + +echo ">>> pushing latest docker image..." +# TODO: user should be some sci-bot or something, not your account. This will do for now though +docker login git.gtz.dk -u agj -p "$DOCKER_TOKEN" +docker push ${OWNER}/sci:latest diff --git a/Makefile b/Makefile index ed533bf..4bf0d8d 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ dist: mkdir -p $(NAME)-$(VERSION) cp -R \ TODO.md README.md\ - Makefile src include\ + Makefile src include scripts\ $(NAME)-$(VERSION) tar -cf - $(NAME)-$(VERSION) | gzip > $(NAME)-$(VERSION).tar.gz rm -rf $(NAME)-$(VERSION) @@ -67,10 +67,13 @@ dist: # use: # make install PREFIX=/custom/path install: out/bin/sci mkdir -p $(DESTDIR)$(PREFIX)/bin + mkdir -p $(DESTDIR)$(PREFIX)/etc/sci # install binaries cp -f out/bin/sci $(DESTDIR)$(PREFIX)/bin chmod 755 $(DESTDIR)$(PREFIX)/bin/sci # install libraries + # install extras + cp -r scripts $(DESTDIR)$(PREFIX)/etc/sci/ # install services (only if system is using systemd though) # install manpages mkdir -p $(DESTDIR)$(MANPREFIX)/man1 diff --git a/TODO.md b/TODO.md index 8c29338..d2f0a82 100644 --- a/TODO.md +++ b/TODO.md @@ -23,7 +23,16 @@ - [ ] Twelveth things last, release! - Setup gitea.gtz.dk (will learn you how to set up subdomains (useful for shop.gtz.dk)) -BOOKMARK: You were reading :Man system.unit and :Man systemd.service as preperation on making a systemd unit file +BOOKMARK: You were getting the following `pipelines.conf` file to work: +``` +scih-dev ssh://git@git.gtz.dk:222/agj/scih.git scih-onpush /etc/sci/scripts/git-clone-and-run-sci-sh.sh +scih-release ssh://git@git.gtz.dk:222/agj/scih.git scih-onrelease /etc/sci/scripts/git-clone-and-run-sci-sh.sh +``` +To get this to work, you need to change some things regarding the packaging - i.e. the `scripts` directory should be +installed as well. Also, you want `sci` to be containerizable. +For the `.sci.sh` script to `docker login`, it will need secrets. Implement those. + +You were reading :Man system.unit and :Man systemd.service as preperation on making a systemd unit file This will be needed for the .deb package, as well as the arch linux package. alpine linux is using OpenRC (cool), which complicates things a little bit, but shouldn't be too bad. The wiki is generally really well written. Otherwise, I am sure that both wiki.gentoo and wiki.archlinux have great pages too @@ -44,6 +53,9 @@ docker is super easy, just make a dockerfile - only concern is the trigger files - [ ] Custom environment variables passed to the pipelines on invokation should be possible. - [ ] Listener threads should be killed and restarted (worker pool should just chug along) when pipeline config file has changed during runtime. Should be disableable with `--no-hot-reload-config` - i.e. on by default. + - [ ] `docker stop` is very slow. I am probably not handling signals properly yet. + - [x] It seems that `-v 4` is segfaulting when running release builds, maybe the logger just cant find the source file? + Nope. I just wrote some bad code (inverted NULL check). ### Note Regarding `inotify` usage From the manpage: diff --git a/deb-builder.dockerfile b/deb-builder.dockerfile index 8a598c3..30ee03d 100644 --- a/deb-builder.dockerfile +++ b/deb-builder.dockerfile @@ -1,9 +1,7 @@ FROM debian:latest -# TODO: Remove busybox from this list once you're done experimenting (you only need vi) RUN apt-get update && apt-get install -y \ build-essential \ devscripts \ - busybox \ dh-make \ uuid-dev \ uuid \ diff --git a/scripts/build-cpp-cmake.sh b/scripts/build-cpp-cmake.sh deleted file mode 100755 index 7d29d9c..0000000 --- a/scripts/build-cpp-cmake.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -set -e # exit immediately on error - -git clone -b dev "$SCI_PIPELINE_URL" "$SCI_PIPELINE_NAME" -echo "clone success" - -cd "$SCI_PIPELINE_NAME" - -cmake -B build -echo "configure success" - -cmake --build build -echo "build success" - -cpack build -echo "packaging success" - -# TODO: upload artifacts to some artifact store -# curl "build/dist/your-package.deb" > ftp://example.com/artifacts -# echo "artifacts upload success" diff --git a/scripts/git-clone-and-run-sci-sh.sh b/scripts/git-clone-and-run-sci-sh.sh new file mode 100644 index 0000000..9d50675 --- /dev/null +++ b/scripts/git-clone-and-run-sci-sh.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +echo ">>> cloning..." +git clone $SCI_PIPELINE_URL $SCI_PIPELINE_NAME +cd $SCI_PIPELINE_NAME + +echo ">>> running .sci.sh..." +time sh .sci.sh diff --git a/scripts/package-sci-arch.sh b/scripts/package-sci-arch.sh deleted file mode 100755 index 35c2d06..0000000 --- a/scripts/package-sci-arch.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -e -echo "building archbuilder image..." -docker build -t archbuilder -f arch-builder.dockerfile . - -echo "building source dist..." -make dist -SRC_SHA256=$(sha256sum sci-1.0.0.tar.gz | awk '{ print $1 }') -echo $SRC_SHA256 -sed "s/SRC_SHA256/$SRC_SHA256/g" < PKGBUILD.in > PKGBUILD - -echo "building arch package in archbuilder docker image..." -docker run --rm -it -v .:/src archbuilder sh -c '\ - cd && \ - cp /src/sci-1.0.0.tar.gz /src/PKGBUILD . && \ - makepkg && \ - cp *.zst /src -' diff --git a/scripts/package-sci-deb.sh b/scripts/package-sci-deb.sh deleted file mode 100755 index cfae038..0000000 --- a/scripts/package-sci-deb.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# TODO: SCI_VERSION env var -set -e -echo "building debbuilder image..." -docker build -t debbuilder -f deb-builder.dockerfile . - -echo "building source dist..." -make dist - -echo "building .deb in debbuilder docker image..." -docker run --rm -it -v .:/src debbuilder sh -c '\ - cd && \ - mkdir -p artifacts && \ - cp /src/sci-1.0.0.tar.gz . && \ - mv sci-1.0.0.tar.gz sci_1.0.0.orig.tar.gz && \ - tar xf sci_1.0.0.orig.tar.gz && \ - cd sci-1.0.0 && \ - cp -r /src/debian . && \ - debuild && \ - cp ../*.deb ~/artifacts && \ - cp ../*.dsc ~/artifacts && \ - cp ../*.build ~/artifacts && \ - cp ../*.buildinfo ~/artifacts && \ - cp ../*.changes ~/artifacts && \ - cp ../*.tar.xz ~/artifacts && \ - cp ../*.tar.gz ~/artifacts && \ - tar czf /src/artifacts.tar.gz ~/artifacts -' diff --git a/src/cli.c b/src/cli.c index 688e7e8..c8b8aa3 100644 --- a/src/cli.c +++ b/src/cli.c @@ -23,24 +23,33 @@ cli_options new_options() { cli_options result; - result.config_file.has_value = false; - result.config_file.value = NULL; + char* config_file = getenv("SCI_CONFIG_FILE"); + result.config_file.has_value = config_file != NULL; + result.config_file.value = config_file; + result.executors = 32; - result.verbosity = 1; + char* verbosity_env = getenv("SCI_VERBOSITY"); + int verbosity = 1; + if(verbosity_env != NULL) + verbosity = atoi(verbosity_env); + result.verbosity = verbosity; + result.help = false; result.version = false; - char *no_color = getenv("NO_COLOR"); - bool color = true; - if(no_color != NULL && no_color[0] != '\0') - color = false; + char* no_color = getenv("NO_COLOR"); + bool color = true; + if(no_color != NULL && no_color[0] != '\0') + color = false; result.use_colors = color; - result.log_file.has_value = false; - result.log_file.value = NULL; + char* log_file = getenv("SCI_LOG_file"); + result.log_file.has_value = log_file != NULL; + result.log_file.value = log_file; - result.pipeline_log_dir.has_value = false; - result.pipeline_log_dir.value = NULL; + char* pipeline_log_dir = getenv("SCI_PIPELINE_LOG_DIR"); + result.pipeline_log_dir.has_value = pipeline_log_dir != NULL; + result.pipeline_log_dir.value = pipeline_log_dir; return result; } @@ -71,6 +80,9 @@ const char* help_msg = " -l file Set sci's log to output to a file\n" " -h Show this message and exit\n" " -V Show version and exit\n" + "\n" + "Most options can also be provided as env variables.\n" + "See sci(1) for more details.\n" ; //