Skip to content

Instantly share code, notes, and snippets.

@killercup
Created December 5, 2019 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killercup/85ca5266c01a8c9159af42bea9aa4feb to your computer and use it in GitHub Desktop.
Save killercup/85ca5266c01a8c9159af42bea9aa4feb to your computer and use it in GitHub Desktop.
stages:
- test
- postprocess
rust builder:
stage: test
image: docker:stable
variables:
CONTAINER_NAME: registry.gitlab.com/PASTE_IN_PROJECT_PATH_HERE/builder:$CI_COMMIT_REF_SLUG
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker build -t $CONTAINER_NAME --build-arg GITLAB_SSH_REPLACMENT_URL="https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/" -f .ci/rust-builder/Dockerfile .
- docker push $CONTAINER_NAME
only:
- /^rust-builder-.*$/i
.cargo-job: &cargo
image: registry.gitlab.com/PASTE_IN_PROJECT_PATH_HERE/builder:rust-builder-2019-12-03
variables:
CARGO_INCREMENTAL: "0"
before_script:
- export PATH="$CARGO_HOME/bin:$PATH"
# for internal git dependencies:
- export CARGO_NET_GIT_FETCH_WITH_CLI=true
- rm ~/.gitconfig && git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf "ssh://git@gitlab.com/"
except:
- /^(\w+)-builder-.*$/i
build and test:
<<: *cargo
stage: test
script:
- cargo build --release --all --verbose
- cargo test --release --all --verbose
- |
mkdir -pv dist && \
ls src/bin/ | xargs -I _ basename _ .rs | xargs -I _ cp /cargo/global-target/release/_ dist/
artifacts:
expire_in: 2 weeks
paths:
- dist/
pretty:
<<: *cargo
stage: postprocess
allow_failure: true
script:
- cargo fmt -- --check
petty:
<<: *cargo
stage: postprocess
script:
- cargo clippy --all
# NOTE: Build this with the context set to a directory that contains a cargo package!
#
# E.g.:
#
# docker build -t test -f .ci/rust-builder/Dockerfile .
FROM rust:1.39.0
# general system dependencies
RUN apt update && \
apt install -y cmake unzip python-pip && \
rm -rf /var/lib/apt/lists/*
# additional rust components
RUN rustup component add rustfmt && rustup component add clippy
RUN mkdir /cargo
ENV CARGO_HOME="/cargo" CARGO_TARGET_DIR="/cargo/global-target" CARGO_INCREMENTAL=0
ADD . /repo-cache
ARG GITLAB_SSH_REPLACMENT_URL
RUN test -n "$GITLAB_SSH_REPLACMENT_URL" && (echo "replacing gitlab ssh url" && git config --global url.$GITLAB_SSH_REPLACMENT_URL.insteadOf "ssh://git@gitlab.com/")
RUN cargo build --release --all --all-targets --manifest-path=/repo-cache/Cargo.toml
RUN cargo clippy --all --all-targets --manifest-path=/repo-cache/Cargo.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment