Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INFRA] Build and use optimized Docker image in Buildkite jobs #7372

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ec3f64d
Splitting Dockerfile to use cached layer.
1Copenut Nov 10, 2023
22104b3
Adding Docker build and push script for CI.
1Copenut Nov 10, 2023
ab49dd8
Refactor pipeline to cache container then run tests.
1Copenut Nov 10, 2023
c10bf65
Simplified shell test commands with yarn deps cached.
1Copenut Nov 10, 2023
2ef2e90
Commented out a11y check. Refactored Docker login routine.
1Copenut Nov 13, 2023
7d4c322
Main merge.
1Copenut Nov 15, 2023
39f604b
Restructured env variables and shell script paths.
1Copenut Nov 15, 2023
9884041
Changing the test image name to be more clear about its purpose.
1Copenut Nov 16, 2023
0962caf
Refactored registry into secrets, removed a few hardcoded strings.
1Copenut Nov 16, 2023
bcd1521
Fixed an incorrect yarn command on a11y test invocation.
1Copenut Nov 16, 2023
d1449b3
Updating local Docker tests.
1Copenut Nov 16, 2023
eec4dd4
Forgot to update Docker image path in test config.
1Copenut Nov 16, 2023
cb30066
Typo in YML file.
1Copenut Nov 16, 2023
0c9234b
Updated script path typos.
1Copenut Nov 16, 2023
7ba378a
Adding Git and SSH deps to slim Docker image.
1Copenut Nov 16, 2023
94fb7bf
Adding non-root user ID.
1Copenut Nov 16, 2023
e528d79
Simplifying yarn invocations in Docker image.
1Copenut Nov 16, 2023
2e06a0b
Typo in the push location.
1Copenut Nov 16, 2023
72b3392
Modifying script to change to app/ directory first to match Docker co…
1Copenut Nov 16, 2023
be96f3c
Adding back GCP to have access to docker CLI commands.
1Copenut Nov 16, 2023
24582f8
Reverted one too many file paths.
1Copenut Nov 16, 2023
83ac87b
Reverting to simpler GCP agent with optimized image.
1Copenut Nov 16, 2023
67acc0e
Last Docker image path update. Fingers crossed.
1Copenut Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions .buildkite/pipelines/pipeline_pull_request_test.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
# 🏠/.buildkite/pipelines/pipeline_pull_request_test.yml

steps:
- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":typescript: Linting"
- label: ":docker: Cached container"
key: "build-test-container"
command: .buildkite/scripts/pipelines/pipeline_docker_build.sh
agents:
provider: "gcp"
if: build.branch != "main" # This job is triggered by the combined test and deploy docs for every PR

- label: ":typescript: Linting"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container" # The depends_on creates an implicit "wait" while the container builds
agents:
provider: "gcp"
env:
TEST_TYPE: 'lint'
if: build.branch != "main" # This job is triggered by the combined test and deploy docs for every PR
if: build.branch != "main"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":jest: TS unit tests"
- label: ":jest: TS unit tests"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
TEST_TYPE: 'unit:ts'
if: build.branch != "main"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":jest: TSX unit tests on React 16"
- label: ":jest: TSX unit tests on React 16"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
TEST_TYPE: 'unit:tsx:16'
if: build.branch != "main"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":jest: TSX unit tests on React 17"
- label: ":jest: TSX unit tests on React 17"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
TEST_TYPE: 'unit:tsx:17'
if: build.branch != "main"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":jest: TSX unit tests on React 18"
- label: ":jest: TSX unit tests on React 18"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
TEST_TYPE: 'unit:tsx'
if: build.branch != "main"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":cypress: Cypress tests on React 16"
- label: ":cypress: Cypress tests on React 16"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
Expand All @@ -52,8 +65,9 @@ steps:
- "cypress/screenshots/**/*.png"
- "cypress/videos/**/*.mp4"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":cypress: Cypress tests on React 17"
- label: ":cypress: Cypress tests on React 17"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
Expand All @@ -63,8 +77,9 @@ steps:
- "cypress/screenshots/**/*.png"
- "cypress/videos/**/*.mp4"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":cypress: Cypress tests on React 18"
- label: ":cypress: Cypress tests on React 18"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
Expand All @@ -74,8 +89,9 @@ steps:
- "cypress/screenshots/**/*.png"
- "cypress/videos/**/*.mp4"

- command: .buildkite/scripts/pipelines/pipeline_test.sh
label: ":axe: Cypress accessibility (a11y) tests on React 18"
- label: ":axe: Cypress accessibility (a11y) tests on React 18"
command: .buildkite/scripts/pipelines/pipeline_test.sh
depends_on: "build-test-container"
agents:
provider: "gcp"
env:
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/scripts/lifecycle/post_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -euo pipefail

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't hurt to have this file, but FYI you shouldn't need it either... The process should exit right after this, so all of the env vars will be gone anyway

set +x

unset GITHUB_ACCOUNT VAULT_ACCOUNT
unset DOCKER_MACHINE DOCKER_STAGING_PASSWORD DOCKER_STAGING_REGISTRY DOCKER_STAGING_USERNAME GCE_ACCOUNT GITHUB_ACCOUNT GITHUB_TOKEN GPROJECT VAULT_ACCOUNT
22 changes: 20 additions & 2 deletions .buildkite/scripts/lifecycle/pre_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@ set +x
echo '[SOURCE]: Buildkite dependencies'
source .buildkite/scripts/common/utils.sh

echo '[INSTALL]: Non-exported variables'
echo '[INSTALL]: env variables'
# ======================================== #
# Paths
# ======================================== #
DOCKER_MACHINE_STAGING=secret/ci/elastic-eui/docker-machine-staging
GITHUB_ACCOUNT=secret/ci/elastic-eui/kibanamachine
VAULT_ACCOUNT=secret/ci/elastic-eui/bekitzur-kibana-service-account

echo '[INSTALL]: Exported variables'
# ======================================== #
# Secrets
# ======================================== #
DOCKER_STAGING_USERNAME=$(retry 5 vault read -field=username $DOCKER_MACHINE_STAGING)
export DOCKER_STAGING_USERNAME

DOCKER_STAGING_PASSWORD=$(retry 5 vault read -field=password $DOCKER_MACHINE_STAGING)
export DOCKER_STAGING_PASSWORD

DOCKER_STAGING_REGISTRY=$(retry 5 vault read -field=registry $DOCKER_MACHINE_STAGING)
export DOCKER_STAGING_REGISTRY

GCE_ACCOUNT=$(retry 5 vault read -field=value $VAULT_ACCOUNT)
export GCE_ACCOUNT

GITHUB_TOKEN=$(retry 5 vault read -field=github_token $GITHUB_ACCOUNT)
export GITHUB_TOKEN

# ======================================== #
# Known values
# ======================================== #
GPROJECT=elastic-bekitzur
export GPROJECT
18 changes: 18 additions & 0 deletions .buildkite/scripts/pipelines/pipeline_docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -euo pipefail
set +x

echo "[DOCKER]: Get registry credentials & login"
if [[ -z "${DOCKER_STAGING_USERNAME}" ]] || [[ -z "${DOCKER_STAGING_PASSWORD}" ]] || [[ -z "${DOCKER_STAGING_REGISTRY}" ]]; then
echo ":fire: Docker credentials not set." 1>&2
exit 1
fi
echo "${DOCKER_STAGING_PASSWORD}" | docker login -u "${DOCKER_STAGING_USERNAME}" --password-stdin "${DOCKER_STAGING_REGISTRY}"

echo "[DOCKER]: Build and push container to registry"
docker-compose -f ./scripts/docker-ci/docker-compose.yml build app
docker push "${DOCKER_STAGING_REGISTRY}"/eui/ci:latest

echo "[DOCKER]: Log out of registry"
docker logout
21 changes: 11 additions & 10 deletions .buildkite/scripts/pipelines/pipeline_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,54 @@ DOCKER_OPTIONS=(
--user="$(id -u):$(id -g)"
--volume="$(pwd):/app"
--workdir=/app
docker.elastic.co/eui/ci:5.6
--platform=linux/amd64
"${DOCKER_STAGING_REGISTRY}"/eui/ci:latest
)

case $TEST_TYPE in
lint)
echo "[TASK]: Running linters"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn lint")
DOCKER_OPTIONS+=(bash -c "yarn lint")
;;

unit:ts)
echo "[TASK]: Running .ts and .js unit tests"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn test-unit --node-options=--max_old_space_size=2048 --testMatch=non-react")
DOCKER_OPTIONS+=(bash -c "yarn test-unit --node-options=--max_old_space_size=2048 --testMatch=non-react")
;;

unit:tsx:16)
echo "[TASK]: Running Jest .tsx tests against React 16"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn test-unit --node-options=--max_old_space_size=2048 --react-version=16 --testMatch=react")
DOCKER_OPTIONS+=(bash -c "yarn test-unit --node-options=--max_old_space_size=2048 --react-version=16 --testMatch=react")
;;

unit:tsx:17)
echo "[TASK]: Running Jest .tsx tests against React 17"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn test-unit --node-options=--max_old_space_size=2048 --react-version=17 --testMatch=react")
DOCKER_OPTIONS+=(bash -c "yarn test-unit --node-options=--max_old_space_size=2048 --react-version=17 --testMatch=react")
;;

unit:tsx)
echo "[TASK]: Running Jest .tsx tests against React 18"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn test-unit --node-options=--max_old_space_size=2048 --testMatch=react")
DOCKER_OPTIONS+=(bash -c "yarn test-unit --node-options=--max_old_space_size=2048 --testMatch=react")
;;

cypress:16)
echo "[TASK]: Running Cypress tests against React 16"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && yarn test-cypress --node-options=--max_old_space_size=2048 --react-version=16")
DOCKER_OPTIONS+=(bash -c "yarn cypress install && yarn test-cypress --node-options=--max_old_space_size=2048 --react-version=16")
;;

cypress:17)
echo "[TASK]: Running Cypress tests against React 17"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && yarn test-cypress --node-options=--max_old_space_size=2048 --react-version=17")
DOCKER_OPTIONS+=(bash -c "yarn cypress install && yarn test-cypress --node-options=--max_old_space_size=2048 --react-version=17")
;;

cypress:18)
echo "[TASK]: Running Cypress tests against React 18"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && yarn test-cypress --node-options=--max_old_space_size=2048")
DOCKER_OPTIONS+=(bash -c "yarn cypress install && yarn test-cypress --node-options=--max_old_space_size=2048")
;;

cypress:a11y)
echo "[TASK]: Running Cypress accessibility tests against React 18"
DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && yarn run test-cypress-a11y --node-options=--max_old_space_size=2048")
DOCKER_OPTIONS+=(bash -c "yarn cypress install && yarn run test-cypress-a11y --node-options=--max_old_space_size=2048")
;;

*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1

# Install latest chrome package and update libs
RUN apt-get update \
&& apt-get install -y wget xvfb ca-certificates gnupg \
&& apt-get install -y wget xvfb ca-certificates gnupg git openssh-client \
--no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
Expand Down
16 changes: 16 additions & 0 deletions scripts/docker-ci/Dockerfile.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:18.18.2-alpine as base

WORKDIR /app

COPY package.json /app/
COPY yarn.lock /app/

RUN apk --no-cache add yarn && yarn

FROM node:18.18.2-alpine as dependencies

WORKDIR /app

COPY --from=base app/package.json /app/
COPY --from=base app/yarn.lock /app/
COPY --from=base app/node_modules /app/node_modules/
17 changes: 17 additions & 0 deletions scripts/docker-ci/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
dependencies:
build:
dockerfile: ./Dockerfile.deps
volumes:
- '.:/app'
- '/app/node_modules'

app:
image: container-registry-test.elastic.co/eui/ci
build:
dockerfile: ./Dockerfile.app
working_dir: /app
volumes_from:
- "dependencies"
depends_on:
- "dependencies"
5 changes: 2 additions & 3 deletions scripts/test-a11y-docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ execSync(
-e GIT_COMMITTER_NAME=test -e GIT_COMMITTER_EMAIL=test -e HOME=/tmp \
--user=$(id -u):$(id -g) \
docker.elastic.co/eui/ci:5.6 \
bash -c '/opt/yarn*/bin/yarn \
&& yarn cypress install \
&& yarn run test-cypress-a11y \
bash -c 'yarn cypress install \
&& yarn test-cypress-a11y \
--node-options=--max_old_space_size=2048 \
--skip-css '", // Skipping CSS because compiling has a tendency to hang on Apple Silicon
{
Expand Down
11 changes: 5 additions & 6 deletions scripts/test-docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ execSync('docker pull docker.elastic.co/eui/ci:5.6', {
});
/* eslint-disable-next-line no-multi-str */
execSync(
'docker run \
-i --rm --cap-add=SYS_ADMIN --volume=$(pwd):/app --workdir=/app \
"docker run \
-i --rm --cap-add=SYS_ADMIN --volume=$(pwd):/app --workdir=/app --platform=linux/amd64 \
-e GIT_COMMITTER_NAME=test -e GIT_COMMITTER_EMAIL=test -e HOME=/tmp \
--user=$(id -u):$(id -g) \
docker.elastic.co/eui/ci:5.6 \
bash -c \'/opt/yarn*/bin/yarn \
&& yarn cypress install \
&& NODE_OPTIONS="--max-old-space-size=2048" npm run test-ci \
&& npm run build\'',
bash -c 'yarn cypress install \
&& yarn test-ci --node-options=--max_old_space_size=2048 \
&& yarn build'",
{
stdio: 'inherit',
}
Expand Down
Loading