feat: add docker image and refactor the scripts

This commit is contained in:
Asger Gitz-Johansen 2024-08-23 18:17:39 +02:00
parent 4d9c1b2a2c
commit ad9dc90f31
10 changed files with 113 additions and 81 deletions

6
.dockerfile Normal file
View File

@ -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"]

59
.sci.sh Executable file
View File

@ -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

View File

@ -57,7 +57,7 @@ dist:
mkdir -p $(NAME)-$(VERSION) mkdir -p $(NAME)-$(VERSION)
cp -R \ cp -R \
TODO.md README.md\ TODO.md README.md\
Makefile src include\ Makefile src include scripts\
$(NAME)-$(VERSION) $(NAME)-$(VERSION)
tar -cf - $(NAME)-$(VERSION) | gzip > $(NAME)-$(VERSION).tar.gz tar -cf - $(NAME)-$(VERSION) | gzip > $(NAME)-$(VERSION).tar.gz
rm -rf $(NAME)-$(VERSION) rm -rf $(NAME)-$(VERSION)
@ -67,10 +67,13 @@ dist:
# use: # make install PREFIX=/custom/path # use: # make install PREFIX=/custom/path
install: out/bin/sci install: out/bin/sci
mkdir -p $(DESTDIR)$(PREFIX)/bin mkdir -p $(DESTDIR)$(PREFIX)/bin
mkdir -p $(DESTDIR)$(PREFIX)/etc/sci
# install binaries # install binaries
cp -f out/bin/sci $(DESTDIR)$(PREFIX)/bin cp -f out/bin/sci $(DESTDIR)$(PREFIX)/bin
chmod 755 $(DESTDIR)$(PREFIX)/bin/sci chmod 755 $(DESTDIR)$(PREFIX)/bin/sci
# install libraries # install libraries
# install extras
cp -r scripts $(DESTDIR)$(PREFIX)/etc/sci/
# install services (only if system is using systemd though) # install services (only if system is using systemd though)
# install manpages # install manpages
mkdir -p $(DESTDIR)$(MANPREFIX)/man1 mkdir -p $(DESTDIR)$(MANPREFIX)/man1

14
TODO.md
View File

@ -23,7 +23,16 @@
- [ ] Twelveth things last, release! - [ ] Twelveth things last, release!
- Setup gitea.gtz.dk (will learn you how to set up subdomains (useful for shop.gtz.dk)) - 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. 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 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 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. - [ ] 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 - [ ] 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. 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 ### Note Regarding `inotify` usage
From the manpage: From the manpage:

View File

@ -1,9 +1,7 @@
FROM debian:latest 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 \ RUN apt-get update && apt-get install -y \
build-essential \ build-essential \
devscripts \ devscripts \
busybox \
dh-make \ dh-make \
uuid-dev \ uuid-dev \
uuid \ uuid \

View File

@ -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"

View File

@ -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

View File

@ -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
'

View File

@ -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
'

View File

@ -23,24 +23,33 @@
cli_options new_options() { cli_options new_options() {
cli_options result; cli_options result;
result.config_file.has_value = false; char* config_file = getenv("SCI_CONFIG_FILE");
result.config_file.value = NULL; result.config_file.has_value = config_file != NULL;
result.config_file.value = config_file;
result.executors = 32; 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.help = false;
result.version = false; result.version = false;
char *no_color = getenv("NO_COLOR"); char* no_color = getenv("NO_COLOR");
bool color = true; bool color = true;
if(no_color != NULL && no_color[0] != '\0') if(no_color != NULL && no_color[0] != '\0')
color = false; color = false;
result.use_colors = color; result.use_colors = color;
result.log_file.has_value = false; char* log_file = getenv("SCI_LOG_file");
result.log_file.value = NULL; result.log_file.has_value = log_file != NULL;
result.log_file.value = log_file;
result.pipeline_log_dir.has_value = false; char* pipeline_log_dir = getenv("SCI_PIPELINE_LOG_DIR");
result.pipeline_log_dir.value = NULL; result.pipeline_log_dir.has_value = pipeline_log_dir != NULL;
result.pipeline_log_dir.value = pipeline_log_dir;
return result; return result;
} }
@ -71,6 +80,9 @@ const char* help_msg =
" -l file Set sci's log to output to a file\n" " -l file Set sci's log to output to a file\n"
" -h Show this message and exit\n" " -h Show this message and exit\n"
" -V Show version 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"
; ;
// <max // <max