Skip to content

Commit

Permalink
Merge pull request #548 from amazonlinux/pipeline-test-stage
Browse files Browse the repository at this point in the history
reauto: pipeline test stage
  • Loading branch information
etungsten authored Dec 2, 2019
2 parents f4d7b26 + f69a717 commit 73fc604
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ RUN --mount=target=/host \
install $(printf "thar-${ARCH}-%s\n" ${PACKAGES}) \
&& mv *.rpm /local/rpms \
&& createrepo_c /local/rpms \
&& /host/bin/rpm2img \
&& /host/tools/rpm2img \
--package-dir=/local/rpms \
--output-dir=/local/output \
&& echo ${NOCACHE}
Expand Down
37 changes: 26 additions & 11 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ skip_core_tasks = true
BUILDSYS_ARCH = { script = ["uname -m"] }
BUILDSYS_ROOT_DIR = "${CARGO_MAKE_WORKING_DIRECTORY}"
BUILDSYS_OUTPUT_DIR = "${BUILDSYS_ROOT_DIR}/build"
BUILDSYS_TOOLS_DIR = "${BUILDSYS_ROOT_DIR}/tools"
BUILDSYS_SOURCES_DIR = "${BUILDSYS_ROOT_DIR}/workspaces"
BUILDSYS_TIMESTAMP = { script = ["date +%s"] }
BUILDSYS_VERSION = { script = ["git describe --tag --dirty || date +%Y%m%d"] }
CARGO_HOME = "${BUILDSYS_ROOT_DIR}/.cargo"
CARGO_MAKE_CARGO_ARGS = "--jobs 8 --offline --locked"
GO_MOD_CACHE = "${BUILDSYS_ROOT_DIR}/.gomodcache"
GO_VERSION = "1.12.5"
DOCKER_BUILDKIT = "1"

[env.development]
Expand Down Expand Up @@ -78,17 +80,30 @@ chmod o+r -R ${CARGO_HOME}
dependencies = ["setup"]
script = [
'''
cd ${BUILDSYS_SOURCES_DIR}/host-ctr/cmd/host-ctr
docker run --rm \
-e GOPRIVATE='*' \
-e GOCACHE='/tmp/.cache' \
--user "$(id -u):$(id -g)" \
${BUILDSYS_DOCKER_RUN_ARGS} \
-v "${GO_MOD_CACHE}":/go/pkg/mod \
-v "${PWD}":/usr/src/host-ctr \
-w /usr/src/host-ctr \
golang:1.12.5 \
bash -c "go list -mod=readonly ./... >/dev/null && go mod vendor"
${BUILDSYS_TOOLS_DIR}/docker-go \
--module-path ${BUILDSYS_SOURCES_DIR}/host-ctr/cmd/host-ctr \
--go-version ${GO_VERSION} \
--go-mod-cache ${GO_MOD_CACHE} \
--command "go list -mod=readonly ./... >/dev/null && go mod vendor"
'''
]

[tasks.unit-tests]
dependencies = ["setup", "fetch-workspaces", "fetch-vendored"]
script = [
'''
cargo test \
${CARGO_BUILD_ARGS} \
${CARGO_MAKE_CARGO_ARGS} \
--manifest-path ${BUILDSYS_SOURCES_DIR}/Cargo.toml \
--all
# host-ctr unit tests (go)
${BUILDSYS_TOOLS_DIR}/docker-go \
--module-path ${BUILDSYS_SOURCES_DIR}/host-ctr/cmd/host-ctr \
--go-version ${GO_VERSION} \
--go-mod-cache ${GO_MOD_CACHE} \
--command "go test -v"
'''
]

Expand Down
66 changes: 66 additions & 0 deletions tools/docker-go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# Helper script for running commands in a golang build/runtime environment for testing/vendoring/building a go module

set -e -o pipefail

usage() {
cat >&2 <<EOF
$(basename "${0}")
--module-path <path to Go module>
--go-version <go version>
--go-mod-cache <path to set up the go mod cache>
--command "<command to run>"
Runs
Required:
--module-path The path of the Go module to mount into the container
--go-version Version of Go to use
--go-mod-cache The Go module cache path to mount into the container
--command The command to run in the golang container
EOF
}

required_arg() {
local arg="${1:?}"
local value="${2}"
if [ -z "${value}" ]; then
echo "ERROR: ${arg} is required" >&2
exit 2
fi
}

parse_args() {
while [ ${#} -gt 0 ] ; do
case "${1}" in
--help ) usage; exit 0 ;;
--module-path ) shift; GO_MODULE_PATH="${1}" ;;
--go-version ) shift; GO_VERSION="${1}" ;;
--go-mod-cache ) shift; GO_MOD_CACHE="${1}" ;;
--command ) shift; COMMAND="${@:1}" ;;
*) ;;
esac
shift
done

# Required arguments
required_arg "--module-path" "${GO_MODULE_PATH}"
required_arg "--go-version" "${GO_VERSION}"
required_arg "--go-mod-cache" "${GO_MOD_CACHE}"
required_arg "--command" "${COMMAND}"
}

DOCKER_RUN_ARGS="--network=host"

parse_args "${@}"

docker run --rm \
-e GOPRIVATE='*' \
-e GOCACHE='/tmp/.cache' \
--user "$(id -u):$(id -g)" \
${DOCKER_RUN_ARGS} \
-v "${GO_MOD_CACHE}":/go/pkg/mod \
-v "${GO_MODULE_PATH}":/usr/src/host-ctr \
-w /usr/src/host-ctr \
golang:${GO_VERSION} \
bash -c "${COMMAND}"
24 changes: 24 additions & 0 deletions tools/infra/buildspec/thar-develop-pipeline-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 0.2

env:
variables:
# Path to infra tooling directory.
INFRA_DIR: "./tools/infra"

phases:
install:
runtime-versions:
docker: 18
commands:
- . "${INFRA_DIR}/env/lib/environment-setup"
- . setup-rust-builder
# TODO: rely on libsystemd in build container instead, see #545
- apt install -y libsystemd-dev
pre_build:
commands:
- environment-report
- write-build-meta
build:
commands:
# Run rust workspaces and go unit tests
- cargo make unit-tests
File renamed without changes.

0 comments on commit 73fc604

Please sign in to comment.