diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index 16c4874..5af92f1 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -31,7 +31,7 @@ node { stage('Build self-ci-java') { sh ''' set -ex - +exit 0 image_tag="$BRANCH_NAME" [ "$image_tag" == "master" ] && image_tag=latest @@ -44,6 +44,22 @@ node { ''' } + stage('Build self-ci-rust') { + sh ''' + set -ex + + image_tag="$BRANCH_NAME" + [ "$image_tag" == "master" ] && image_tag=latest + + cd rust + + # build our image + docker build -t "moparisthebest/self-ci-rust:$image_tag" . + + cd .. + ''' + } + stage('Push to docker hub') { sh ''' set -ex @@ -53,7 +69,8 @@ node { # push our images, don't forget to docker login docker push "moparisthebest/self-ci-base:$image_tag" - docker push "moparisthebest/self-ci-java:$image_tag" + #docker push "moparisthebest/self-ci-java:$image_tag" + docker push "moparisthebest/self-ci-rust:$image_tag" ''' } diff --git a/java/readme.md b/java/readme.md index 078950f..84d4586 100644 --- a/java/readme.md +++ b/java/readme.md @@ -6,11 +6,11 @@ A docker container with every version of the Java JDK 6 to 16 installed in it, a Meant to be ran in CI something like this: ```sh -docker run --rm -v "$HOME/.m2:/m2" -v "$PWD:/build" -e BRANCH_NAME -e BUILD_UID=$UID -e BUILD_GID=$(id -g) moparisthebest/java-ci:latest +docker run --rm -v "$HOME/.m2:/m2" -v "$PWD:/build" -e BRANCH_NAME -e BUILD_UID=$UID -e BUILD_GID=$(id -g) moparisthebest/self-ci-java:latest ``` Without arguments it will execute `.jenkins/build.sh` once for each version of Java installed, setting the env variables JAVA_VERSION (a number), JAVA_HOME, M2_HOME, and PATH appropriately so invocations of `mvn` and `java` *just work*. If you want to call another script each time: ```sh -docker run --rm -v "$HOME/.m2:/m2" -v "$PWD:/build" -e BRANCH_NAME -e BUILD_UID=$UID -e BUILD_GID=$(id -g) moparisthebest/java-ci:latest build.sh ./path/to/your/script.sh +docker run --rm -v "$HOME/.m2:/m2" -v "$PWD:/build" -e BRANCH_NAME -e BUILD_UID=$UID -e BUILD_GID=$(id -g) moparisthebest/self-ci-java:latest build.sh ./path/to/your/script.sh ``` diff --git a/readme.md b/readme.md index f52ad8c..914b32c 100644 --- a/readme.md +++ b/readme.md @@ -5,4 +5,4 @@ self-ci This is one of the steps in fully replacing travis-ci for my own uses, but feel free to use/PR/improve. -todo: point to self-ci-java etc \ No newline at end of file +todo: point to self-ci-java, rust etc \ No newline at end of file diff --git a/run.sh b/run.sh index b786db9..ce77919 100755 --- a/run.sh +++ b/run.sh @@ -7,8 +7,10 @@ if [ ! -z "${BUILD_UID:-}" ] then BUILD_GID="${BUILD_GID:-$BUILD_UID}" groupadd -r -g "$BUILD_GID" jenkins - useradd -r -u "$BUILD_UID" -g "$BUILD_GID" -s /bin/bash -m -d /root jenkins - chown "$BUILD_UID":"$BUILD_GID" /root + additional_groups='' + [ -e /var/run/docker.sock ] && additional_groups="-G $(stat -c '%g' /var/run/docker.sock)" + useradd -r -u "$BUILD_UID" -g "$BUILD_GID" $additional_groups -s /bin/bash -m -d /root jenkins + chown -R "$BUILD_UID":"$BUILD_GID" /root #exec runuser -m jenkins -- "$@" exec sudo -E -u jenkins -- "$@" fi diff --git a/rust/Dockerfile b/rust/Dockerfile new file mode 100644 index 0000000..cbabff4 --- /dev/null +++ b/rust/Dockerfile @@ -0,0 +1,18 @@ + +FROM moparisthebest/self-ci-base:latest + +# set CROSS_DOCKER_IN_DOCKER to inform `cross` that it is executed from within a container +#ENV CROSS_DOCKER_IN_DOCKER=true + +RUN mkdir /cargo && ln -sf /cargo/ /root/.cargo && \ + pacman -Syu --noconfirm --needed docker rustup gcc && \ + rustup install stable && rustup default stable && \ + cargo install --root / cross + +COPY ./build.sh /usr/bin/ + +VOLUME [ "/build", "/var/run/docker.sock" ] + +WORKDIR /build +ENTRYPOINT ["/usr/bin/run.sh"] +CMD ["/usr/bin/build.sh", "./.jenkins/build.sh"] diff --git a/rust/build.sh b/rust/build.sh new file mode 100755 index 0000000..f4befc5 --- /dev/null +++ b/rust/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +for TARGET in ${BUILD_TARGETS:-x86_64-unknown-linux-musl} +do + TARGET="$TARGET" "$@" +done diff --git a/rust/readme.md b/rust/readme.md new file mode 100644 index 0000000..90e6879 --- /dev/null +++ b/rust/readme.md @@ -0,0 +1,16 @@ +self-ci-rust +------------ + +A docker container with rustup and [cross](https://github.com/rust-embedded/cross) that runs a script with every variant cross supports. + +Meant to be ran in CI something like this: + +```sh +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD:/build" -e BRANCH_NAME -e BUILD_UID=$UID -e BUILD_GID=$(id -g) moparisthebest/self-ci-rust:latest +``` + +Without arguments it will execute `.jenkins/build.sh` once for each docker container cross supports, setting the env variables TARGET and DISABLE_TESTS appropriately so invocations of `cross` and `cargo` *just work*. If you want to call another script each time: + +```sh +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD:/build" -e BRANCH_NAME -e BUILD_UID=$UID -e BUILD_GID=$(id -g) moparisthebest/self-ci-rust:latest build.sh ./path/to/your/script.sh +```