Skip to content

Commit cf442df

Browse files
author
Mudit
authored
BuildKite CI (#40)
* BuildKite CI
1 parent affd2cd commit cf442df

File tree

7 files changed

+166
-5
lines changed

7 files changed

+166
-5
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
agent_queue_id: trigger-pipelines
2+
description: C Example Project premerge pipeline
3+
github:
4+
branch_configuration: []
5+
default_branch: master
6+
pull_request_branch_filter_configuration: []
7+
teams:
8+
- name: Everyone
9+
permission: BUILD_AND_READ
10+
- name: spatialos-eng/worker
11+
permission: MANAGE_BUILD_AND_READ

.buildkite/premerge.steps.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
common: &common
2+
timeout_in_minutes: 60
3+
retry:
4+
automatic:
5+
# These are designed to trap and retry failures because agent lost connection.
6+
# Agent exits with -1 in this case.
7+
- exit_status: -1
8+
limit: 3
9+
- exit_status: 255
10+
limit: 3
11+
- exit_status: 128
12+
limit: 3
13+
14+
linux_agent: &linux_agent
15+
agents:
16+
- "agent_count=1"
17+
- "capable_of_building=worker-sdk"
18+
- "environment=production"
19+
- "permission_set=builder"
20+
- "platform=linux"
21+
- "scaler_version=2"
22+
- "machine_type=half"
23+
- "queue=${CI_LINUX_BUILDER_QUEUE:-v4-20-03-23-110204-bk9814-9f960b76}"
24+
<<: *common
25+
26+
macos_agent: &macos_agent
27+
agents:
28+
- "queue=${CI_MACOS_BUILDER_QUEUE:-macos_worker-sdk_17b57b101ca8ff76}"
29+
- "environment=production"
30+
<<: *common
31+
32+
windows_agent: &windows_agent
33+
agents:
34+
- "agent_count=1"
35+
- "capable_of_building=worker-sdk"
36+
- "environment=production"
37+
- "machine_type=half"
38+
- "permission_set=builder"
39+
- "platform=windows"
40+
- "scaler_version=2"
41+
- "queue=${CI_WINDOWS_BUILDER_QUEUE:-v4-20-03-25-183029-bk9912-014014bb}"
42+
<<: *common
43+
44+
steps:
45+
- label: "build-linux"
46+
command: "ci/build.sh"
47+
<<: *linux_agent
48+
- label: "build-macos"
49+
command: "ci/build.sh"
50+
<<: *macos_agent
51+
- label: "build-windows"
52+
command: "bash -c ci/build.sh"
53+
<<: *windows_agent
54+

.toolsharerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pinned_tool:
2+
- tool: "imp-ci"
3+
version: "20200206.175502.ed41e47ac7"
4+
- tool: "imp-tool"
5+
version: "20200217.173900.11796cb28c"

ci/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update \
4+
&& apt-get install -y \
5+
cmake \
6+
g++ \
7+
gcc \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
ARG USER_ID
11+
ARG GROUP_ID
12+
13+
RUN addgroup --gid $GROUP_ID user \
14+
&& adduser --disabled-password --uid $USER_ID --gid $GROUP_ID user
15+
USER user

ci/build.sh

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,85 @@ set -e -u -x -o pipefail
44

55
cd "$(dirname "$0")/.."
66

7-
PLATFORM=""
7+
if [[ -z ${BUILDKITE+x} ]]; then
8+
echo "This script is intended to run in CI only."
9+
exit 1
10+
fi
11+
12+
SPATIALOS_TOOLBELT_VERSION="latest"
13+
14+
TOOLBELT_PLATFORM=""
15+
SPATIAL_PLATFORM=""
16+
SPATIAL_BINARY=""
17+
18+
# Setup platform specific environment variables.
819
if [[ "$(uname -s)" == "Linux" ]]; then
9-
PLATFORM="linux"
20+
TOOLBELT_PLATFORM="linux"
21+
SPATIAL_PLATFORM="linux"
22+
SPATIAL_BINARY="spatial"
1023
elif [[ "$(uname -s)" == "Darwin" ]]; then
11-
PLATFORM="macos"
24+
TOOLBELT_PLATFORM="mac"
25+
SPATIAL_PLATFORM="macos"
26+
SPATIAL_BINARY="spatial"
27+
28+
imp-tool-bootstrap subscribe \
29+
--use_gcs_oidc_auth=false \
30+
--gcs_credentials_type=auto \
31+
--tools=imp-tool
32+
else
33+
TOOLBELT_PLATFORM="win"
34+
SPATIAL_PLATFORM="windows"
35+
SPATIAL_BINARY="spatial.exe"
36+
fi
37+
38+
# Create temporary directories for the spatial binary and authentication token.
39+
export AUTH_DIR="$(mktemp -d)"
40+
export TOOLS_DIR="$(mktemp -d)"
41+
42+
# Retrieve the authentication token.
43+
if [[ "$SPATIAL_PLATFORM" == "macos" ]]; then
44+
imp-vault read-key \
45+
--environment=production \
46+
--field=token \
47+
--key=secret/sync.v1/dev-workflow/production-buildkite/buildkite-agents/spatialos-service-account/ci/improbable/worker-blank-projects-ci-token \
48+
--vault_role=continuous-integration-production-improbable-iam \
49+
--write_to="${AUTH_DIR}/oauth2_refresh_token"
50+
else
51+
imp-ci secrets read \
52+
--environment=production \
53+
--buildkite-org=improbable \
54+
--secret-type=spatialos-service-account \
55+
--secret-name=worker-blank-projects-ci-token \
56+
--field=token \
57+
--write-to="${AUTH_DIR}/oauth2_refresh_token"
58+
fi
59+
60+
# Retrieve the spatial binary.
61+
curl -Ls -o "${TOOLS_DIR}/${SPATIAL_BINARY}.tmp" "https://console.improbable.io/toolbelt/download/${SPATIALOS_TOOLBELT_VERSION}/${TOOLBELT_PLATFORM}" || exit 1
62+
chmod +x "${TOOLS_DIR}/${SPATIAL_BINARY}.tmp"
63+
mv "${TOOLS_DIR}/${SPATIAL_BINARY}.tmp" "${TOOLS_DIR}/${SPATIAL_BINARY}"
64+
65+
# Build
66+
if [[ "$SPATIAL_PLATFORM" == "linux" ]]; then
67+
docker build \
68+
-t c_exampe_project_image \
69+
-f ci/Dockerfile \
70+
--build-arg USER_ID=$(id -u) \
71+
--build-arg GROUP_ID=$(id -g) \
72+
.
73+
docker run \
74+
--rm \
75+
--volume "${TOOLS_DIR}":/build/tools \
76+
--env TOOLS_DIR=/build/tools \
77+
--volume "${AUTH_DIR}":/build/auth \
78+
--env AUTH_DIR=/build/auth \
79+
--volume $(pwd):/code \
80+
--workdir /code \
81+
c_exampe_project_image \
82+
/bin/bash -c 'export PATH="/code/ci:${PATH}"; \
83+
spatial build --target '"$SPATIAL_PLATFORM"
1284
else
13-
PLATFORM="windows"
85+
# Add the spatial wrapper script to the path.
86+
export PATH="$(pwd)/ci":"$PATH"
87+
spatial build --target $SPATIAL_PLATFORM
1488
fi
15-
spatial build --target $PLATFORM --log_level=debug

ci/spatial

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
"${TOOLS_DIR}"/spatial --log_level=debug --oauth2_client_cli_token_directory="${AUTH_DIR}" "$@"

ci/spatial.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bash "%~dp0spatial" %*

0 commit comments

Comments
 (0)