From b9cfdb1fd57032f2716c46ea5f3a8e06ba877881 Mon Sep 17 00:00:00 2001 From: belliash Date: Sun, 24 Jul 2022 22:38:42 +0200 Subject: [PATCH] Import OSCW runner --- .build.yml | 11 +++++++++++ Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ README.md | 3 +++ files/entrypoint.sh | 21 +++++++++++++++++++++ files/github_publish | 22 ++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 .build.yml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 files/entrypoint.sh create mode 100644 files/github_publish diff --git a/.build.yml b/.build.yml new file mode 100644 index 0000000..295efce --- /dev/null +++ b/.build.yml @@ -0,0 +1,11 @@ +pipeline: + build: + image: codingworkshop/oscw-runner:latest + secrets: + - OSCW_DOCKERHUB_USERNAME + - OSCW_DOCKERHUB_PASSWORD + commands: + - echo $OSCW_DOCKERHUB_PASSWORD | docker login -u $OSCW_DOCKERHUB_USERNAME --password-stdin + - docker build -t codingworkshop/oscw-runner:latest . + - docker push codingworkshop/oscw-runner:latest + - docker image prune -af diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..27162f7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM archlinux:latest +MAINTAINER CodingWorkshop + +# Update system base +RUN pacman -Syu --noconfirm --noprogressbar --quiet + +# Install additional packages +RUN pacman -Syu --noconfirm --noprogressbar --quiet autoconf automake binutils bison cppcheck docker flex gcc git libedit libmd linux-headers patch pkgconfig texinfo wget + +# Set locale +RUN echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen && \ + echo 'LANG=en_US.UTF-8' > /etc/locale.conf && \ + locale-gen + +# Install Docker-in-Docker +ENV DIND_COMMIT 3b5fac462d21ca164b3778647420016315289034 +RUN wget "https://raw.githubusercontent.com/docker/docker/${DIND_COMMIT}/hack/dind" -O /usr/local/bin/dind && \ + chmod a+x /usr/local/bin/dind + +# Configure Docker-in-Docker +COPY files/entrypoint.sh /usr/local/bin/ +RUN chmod a+x /usr/local/bin/entrypoint.sh +VOLUME /var/lib/docker +EXPOSE 2375 + +# Install XT toolchain +RUN wget https://github.com/xt-sys/xtchain/releases/download/2.2/xtchain-2.2-linux.tar.zst -O xtchain.tar.zst && \ + mkdir -p /opt/xtchain && \ + tar xapf xtchain.tar.zst -C /opt/xtchain && \ + rm xtchain.tar.zst + +# Install GitHub publishing script +COPY files/github_publish /usr/local/bin/ +RUN chmod a+x /usr/local/bin/github_publish + +# Set system path +ENV PATH="/opt/xtchain:/opt/xtchain/bin:${PATH}" + +# Set default entrypoint +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD [] diff --git a/README.md b/README.md new file mode 100644 index 0000000..31357f7 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# OSCW Runner +OSCW runner is an official build container for CodingWorkshop projects that include classic GNU toolchain and XTChain. +It is based on the latest version of the Arch Linux base container. It is designed for use on the OSCW CI/CD platform. diff --git a/files/entrypoint.sh b/files/entrypoint.sh new file mode 100644 index 0000000..926af76 --- /dev/null +++ b/files/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +# no arguments passed +# or first arg is `-f` or `--some-option` +if [ "$#" -eq 0 -o "${1#-}" != "$1" ]; then + # add our default arguments + set -- dockerd \ + --host=unix:///var/run/docker.sock \ + --host=tcp://0.0.0.0:2375 \ + --storage-driver=vfs \ + "$@" +fi + +if [ "$1" = 'dockerd' ]; then + # if we're running Docker, let's pipe through dind + # (and we'll run dind explicitly with "sh" since its shebang is /bin/bash) + set -- sh "$(which dind)" "$@" +fi + +exec "$@" diff --git a/files/github_publish b/files/github_publish new file mode 100644 index 0000000..f39aec4 --- /dev/null +++ b/files/github_publish @@ -0,0 +1,22 @@ +#!/bin/bash + +GITHUB_USERNAME="${1}" +GITHUB_TOKEN="${2}" +ASSET_NAME="${3}" + +echo "Creating new GitHub release '${CI_COMMIT_TAG}'" +RESULT=$(curl --user "${GITHUB_USERNAME}:${GITHUB_TOKEN}" -X POST https://api.github.com/repos/${CI_REPO}/releases -d \ + "{ + \"tag_name\": \"${CI_COMMIT_TAG}\", + \"target_commitish\": \"${CI_COMMIT_SHA}\", + \"name\": \"${CI_COMMIT_TAG}\", + \"draft\": false, + \"prerelease\": false + }") + +echo "Create release result: ${RESULT}" +RELEASE_ID=$(echo "${RESULT}" | python -c 'import json,sys;print(json.load(sys.stdin)["id"])') + +echo "Publishing artifact: ${ASSET_NAME}" +curl --user "${GITHUB_USERNAME}:${GITHUB_TOKEN}" -X POST https://uploads.github.com/repos/${CI_REPO}/releases/${RELEASE_ID}/assets?name=${ASSET_NAME} \ + --header 'Content-Type: text/javascript ' --upload-file ${ASSET_NAME}