From ea5e31c2799b7575b8c5db2c9a83080eaf7b7bdc Mon Sep 17 00:00:00 2001 From: Mikail Bagishov Date: Sat, 8 May 2021 21:21:19 +0300 Subject: [PATCH] Add artifact Generated image contains pps-cli binary and preconfigured build environment. --- .dockerignore | 2 ++ .github/workflows/publish.yaml | 23 +++++++++++++++++++++++ .gitignore | 1 + build-env/Dockerfile | 21 +++++++++++++++++++++ build-env/Readme.md | 9 +++++++++ make-build-env.py => build-env/make.py | 11 ++++++----- ci/config.yaml | 4 ++-- ci/e2e-run.sh | 2 +- ci/publish-build.sh | 3 +++ ci/publish-images.sh | 16 ++++++++++++++++ 10 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100755 .github/workflows/publish.yaml create mode 100644 .gitignore create mode 100644 build-env/Dockerfile create mode 100644 build-env/Readme.md rename make-build-env.py => build-env/make.py (84%) create mode 100644 ci/publish-build.sh create mode 100755 ci/publish-images.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..77b444d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/target +Readme.md diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100755 index 0000000..366bea8 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,23 @@ +# GENERATED FILE DO NOT EDIT +name: publish +"on": + pull_request: {} + push: + branches: + - staging + - trying + - master +jobs: + publish: + if: github.event_name == 'push' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + runs-on: ubuntu-20.04 + timeout-minutes: 15 + steps: + - name: Fetch sources + uses: actions/checkout@v2 + - name: Build artifacts + run: bash ci/publish-build.sh + - name: Publish docker images + run: bash ci/publish-images.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/build-env/Dockerfile b/build-env/Dockerfile new file mode 100644 index 0000000..2c44c7e --- /dev/null +++ b/build-env/Dockerfile @@ -0,0 +1,21 @@ +# Build context: parent directory +FROM rust:slim-bullseye as create-build-env +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc g++ cmake python3 make +COPY . /pps +WORKDIR /pps +ENV PYTHONUNBUFFERED=1 +RUN python3 ./build-env/make.py --out /build-env + +FROM rust:slim as build-pps +COPY . /pps +WORKDIR /pps +RUN cargo install --path cli + +FROM ubuntu:focal +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc g++ cmake python3 make +WORKDIR /usr/local/bin +COPY --from=build-pps /usr/local/cargo/bin/pps-cli pps-cli +COPY --from=create-build-env /build-env /opt/pps-build-env +ENV JJS_PATH=/opt/pps-build-env diff --git a/build-env/Readme.md b/build-env/Readme.md new file mode 100644 index 0000000..c4732a5 --- /dev/null +++ b/build-env/Readme.md @@ -0,0 +1,9 @@ +# Build environment + +Build environment is files which are used when pss compiles problems. + +## Creation + +`make.py` is a script that creates environment locally. + +`Dockerfile` defines container image with an environment and other necessary tools. diff --git a/make-build-env.py b/build-env/make.py similarity index 84% rename from make-build-env.py rename to build-env/make.py index 021a2ac..6ac58c2 100644 --- a/make-build-env.py +++ b/build-env/make.py @@ -3,6 +3,7 @@ import argparse import tempfile import os +import os.path import subprocess import shutil @@ -17,16 +18,16 @@ def main(args): subprocess.run(["cargo", "build", "-p", "svaluer", "-Zunstable-options", "--out-dir", f"{args.tmp}"], env=env, check=True) shutil.copy(f"{args.tmp}/svaluer", f"{args.out}/bin/svaluer") if "jtl" in args.filter: + install_dir = os.path.realpath(args.out) + print("Configuring JTL") + subprocess.run(["cmake", "-S", f"{args.source}/jtl", "-B", f"{args.tmp}/cmake", f"-DCMAKE_INSTALL_PREFIX={install_dir}"], check=True) print("Building JTL") - subprocess.run(["cmake", "-S", f"{args.source}/jtl", "-B", f"{args.tmp}/cmake", f"-DCMAKE_INSTALL_PREFIX={args.out}"], check=True) subprocess.run(["cmake", "--build", f"{args.tmp}/cmake"], check=True) + print(f"Installing JTL to {install_dir}") subprocess.run(["cmake", "--install", f"{args.tmp}/cmake"], check=True) DESCRIPTION = ''' -Script that compiles PPS problem build environment. - -This environment contains files that are used when compiling or -importing problems. +Script that creates PPS problem build environment. ''' parser = argparse.ArgumentParser(description=DESCRIPTION) diff --git a/ci/config.yaml b/ci/config.yaml index 3962a95..d9ff229 100644 --- a/ci/config.yaml +++ b/ci/config.yaml @@ -1,3 +1,3 @@ -# TODO: add artifacts -noPublish: true +dockerImages: + - pps-cli buildTimeoutMinutes: 15 diff --git a/ci/e2e-run.sh b/ci/e2e-run.sh index 27f49b9..5df2d03 100644 --- a/ci/e2e-run.sh +++ b/ci/e2e-run.sh @@ -3,7 +3,7 @@ set -euxo pipefail sudo chmod +x ./e2e-artifacts/pps-cli -python3 make-build-env.py --out $HOME/build-env +python3 build-env/make.py --out $HOME/build-env export JJS_PATH=$HOME/build-env for i in a-plus-b array-sum sqrt; do mkdir -p ./out/$i diff --git a/ci/publish-build.sh b/ci/publish-build.sh new file mode 100644 index 0000000..42c6e39 --- /dev/null +++ b/ci/publish-build.sh @@ -0,0 +1,3 @@ +set -euxo pipefail +export DOCKER_BUILDKIT=1 +docker build -f build-env/Dockerfile -t pps-cli . \ No newline at end of file diff --git a/ci/publish-images.sh b/ci/publish-images.sh new file mode 100755 index 0000000..e760e3a --- /dev/null +++ b/ci/publish-images.sh @@ -0,0 +1,16 @@ +set -euxo pipefail + +# GENERATED FILE DO NOT EDIT +if [ "$GITHUB_REF" = "refs/heads/master" ] +then + TAG="latest" +elif [ "$GITHUB_REF" = "refs/heads/trying" ] +then + TAG="dev" +else + echo "unknown GITHUB_REF: $GITHUB_REF" + exit 1 +fi +echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin +docker tag pps-cli ghcr.io/jjs-dev/pps-cli:$TAG +docker push ghcr.io/jjs-dev/pps-cli:$TAG \ No newline at end of file