From 9ef1b0908296f1c5b2312bc3e57f3eafba5068fb Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 17 Oct 2024 16:32:34 -0500 Subject: [PATCH 01/17] test(analyses-snapshot): add capability to run against local code --- analyses-snapshot-testing/Makefile | 58 +++++++++++++++---- analyses-snapshot-testing/README.md | 9 +++ .../citools/Dockerfile.local | 25 ++++++++ .../citools/generate_analyses.py | 11 +++- 4 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 analyses-snapshot-testing/citools/Dockerfile.local diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index fff00bbe3c1..30adfbcd5a7 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -1,22 +1,28 @@ +ifeq ($(CI), true) + PYTHON=python +else + PYTHON=pyenv exec python +endif + .PHONY: black black: - python -m pipenv run python -m black . + $(PYTHON) -m pipenv run python -m black . .PHONY: black-check black-check: - python -m pipenv run python -m black . --check + $(PYTHON) -m pipenv run python -m black . --check .PHONY: ruff ruff: - python -m pipenv run python -m ruff check . --fix + $(PYTHON) -m pipenv run python -m ruff check . --fix .PHONY: ruff-check ruff-check: - python -m pipenv run python -m ruff check . + $(PYTHON) -m pipenv run python -m ruff check . .PHONY: mypy mypy: - python -m pipenv run python -m mypy automation tests citools + $(PYTHON) -m pipenv run python -m mypy automation tests citools .PHONY: lint lint: black-check ruff-check mypy @@ -32,7 +38,7 @@ format: .PHONY: test-ci test-ci: - python -m pipenv run python -m pytest -m "emulated_alpha" + $(PYTHON) -m pipenv run python -m pytest -m "emulated_alpha" .PHONY: test-protocol-analysis test-protocol-analysis: @@ -40,11 +46,11 @@ test-protocol-analysis: .PHONY: setup setup: install-pipenv - python -m pipenv install + $(PYTHON) -m pipenv install .PHONY: teardown teardown: - python -m pipenv --rm + $(PYTHON) -m pipenv --rm .PHONY: format-readme format-readme: @@ -52,7 +58,7 @@ format-readme: .PHONY: install-pipenv install-pipenv: - python -m pip install -U pipenv + $(PYTHON) -m pip install -U pipenv ANALYSIS_REF ?= edge PROTOCOL_NAMES ?= all @@ -67,14 +73,14 @@ snapshot-test: @echo "ANALYSIS_REF is $(ANALYSIS_REF)" @echo "PROTOCOL_NAMES is $(PROTOCOL_NAMES)" @echo "OVERRIDE_PROTOCOL_NAMES is $(OVERRIDE_PROTOCOL_NAMES)" - python -m pipenv run pytest -k analyses_snapshot_test -vv + $(PYTHON) -m pipenv run pytest -k analyses_snapshot_test -vv .PHONY: snapshot-test-update snapshot-test-update: @echo "ANALYSIS_REF is $(ANALYSIS_REF)" @echo "PROTOCOL_NAMES is $(PROTOCOL_NAMES)" @echo "OVERRIDE_PROTOCOL_NAMES is $(OVERRIDE_PROTOCOL_NAMES)" - python -m pipenv run pytest -k analyses_snapshot_test --snapshot-update + $(PYTHON) -m pipenv run pytest -k analyses_snapshot_test --snapshot-update CACHEBUST := $(shell date +%s) @@ -88,7 +94,7 @@ build-opentrons-analysis: .PHONY: generate-protocols generate-protocols: - python -m pipenv run python -m automation.data.protocol_registry + $(PYTHON) -m pipenv run python -m automation.data.protocol_registry OPENTRONS_VERSION ?= edge @@ -112,3 +118,31 @@ run-ot2: @echo "Running opentrons-robot-server:$(OPENTRONS_VERSION)" @echo "If you want to run a different version, run 'make run-ot2 OPENTRONS_VERSION=chore_release-8.0.0'" docker run -p 31950:31950 --env-file ../robot-server/dev.env opentrons-robot-server:$(OPENTRONS_VERSION) + +BUILD_FLAGS := $(if $(NO_CACHE),--no-cache) + +.PHONY: local-build +local-build: + @echo "Building docker image for your local opentrons code" + @echo "The image will be named opentrons-analysis:local" + @echo "For a fresh build, run 'make local-build NO_CACHE=1'" + sed -i.bak '/^.git/s/^/#/' ../.dockerignore || true + docker build $(BUILD_FLAGS) -t opentrons-analysis:local -f citools/Dockerfile.local .. || true + mv ../.dockerignore.bak ../.dockerignore || true + @echo "Build complete" + +.PHONY: local-snapshot-test +local-snapshot-test: + @echo "Running against local opentrons-analysis:local" + @echo "You must run this command like 'make local-snapshot-test ANALYSIS_REF=local'" + @echo "This is because the test suite reads the ANALYSIS_REF environment variable." + @echo "And uses it to determine which image to run against." + @echo "ANALYSIS_REF is $(ANALYSIS_REF)" + @if [ "$(ANALYSIS_REF)" = "local" ]; then \ + echo "ANALYSIS_REF is correctly set to 'local'"; \ + else \ + echo "Warning: ANALYSIS_REF is not set to 'local'"; \ + fi + @echo "PROTOCOL_NAMES is $(PROTOCOL_NAMES)" + @echo "OVERRIDE_PROTOCOL_NAMES is $(OVERRIDE_PROTOCOL_NAMES)" + $(PYTHON) -m pipenv run pytest -k analyses_snapshot_test -vv diff --git a/analyses-snapshot-testing/README.md b/analyses-snapshot-testing/README.md index 51a8e194ca1..cd9a230bc16 100644 --- a/analyses-snapshot-testing/README.md +++ b/analyses-snapshot-testing/README.md @@ -58,3 +58,12 @@ cd analyses-snapshot-testing \ ### Default OPENTRONS_VERSION=edge in the Makefile so you can omit it if you want latest edge `cd analyses-snapshot-testing && make build-rs && make run-rs` + +## Running the Analyses Battery against your local code + +1. `make build-local` +1. `make local-snapshot-test` + +You have the option to specify one or many protocols to run the analyses on. This is also described above [Running the tests against specific protocols](#running-the-tests-against-specific-protocols) + +- `make local-snapshot-test PROTOCOL_NAMES=Flex_S_v2_19_Illumina_DNA_PCR_Free OVERRIDE_PROTOCOL_NAMES=none` diff --git a/analyses-snapshot-testing/citools/Dockerfile.local b/analyses-snapshot-testing/citools/Dockerfile.local new file mode 100644 index 00000000000..34e695e2c1f --- /dev/null +++ b/analyses-snapshot-testing/citools/Dockerfile.local @@ -0,0 +1,25 @@ +# Use Python 3.10, same as the app +FROM python:3.10-slim-bullseye + +# Update packages and install required dependencies +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y git libsystemd-dev + +# Set the working directory in the container +WORKDIR /opentrons + +# Copy everything from the build context into the /opentrons directory +COPY . /opentrons + +# List the contents of the /opentrons directory to verify the .git folder is copied +RUN ls -al /opentrons/.git + +# Install required packages from the copied code +RUN python -m pip install -U ./shared-data/python +RUN python -m pip install -U ./hardware[flex] +RUN python -m pip install -U ./api +RUN python -m pip install -U pandas==1.4.3 + +# The default command to keep the container running +CMD ["tail", "-f", "/dev/null"] diff --git a/analyses-snapshot-testing/citools/generate_analyses.py b/analyses-snapshot-testing/citools/generate_analyses.py index f67d0394429..7e4aa2281ea 100644 --- a/analyses-snapshot-testing/citools/generate_analyses.py +++ b/analyses-snapshot-testing/citools/generate_analyses.py @@ -24,7 +24,7 @@ HOST_RESULTS: Path = Path(Path(__file__).parent.parent, "analysis_results") ANALYSIS_SUFFIX: str = "analysis.json" ANALYSIS_TIMEOUT_SECONDS: int = 30 -ANALYSIS_CONTAINER_INSTANCES: int = 5 +MAX_ANALYSIS_CONTAINER_INSTANCES: int = 5 console = Console() @@ -240,6 +240,12 @@ def analyze_against_image(tag: str, protocols: List[TargetProtocol], num_contain return protocols +def get_container_instances(protocol_len: int) -> int: + # Scaling linearly with the number of protocols + instances = max(1, min(MAX_ANALYSIS_CONTAINER_INSTANCES, protocol_len // 10)) + return instances + + def generate_analyses_from_test(tag: str, protocols: List[Protocol]) -> None: """Generate analyses from the tests.""" start_time = time.time() @@ -259,6 +265,7 @@ def generate_analyses_from_test(tag: str, protocols: List[Protocol]) -> None: protocol_custom_labware_paths_in_container(test_protocol), ) ) - analyze_against_image(tag, protocols_to_process, ANALYSIS_CONTAINER_INSTANCES) + instance_count = get_container_instances(len(protocols_to_process)) + analyze_against_image(tag, protocols_to_process, instance_count) end_time = time.time() console.print(f"Clock time to generate analyses: {end_time - start_time:.2f} seconds.") From 5b278376defefde97faeb9b6973d71e47ea72398 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Fri, 18 Oct 2024 08:44:51 -0500 Subject: [PATCH 02/17] no git needed --- analyses-snapshot-testing/Makefile | 2 -- analyses-snapshot-testing/citools/Dockerfile.local | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index e6041e11f76..a4f2a910e95 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -126,9 +126,7 @@ local-build: @echo "Building docker image for your local opentrons code" @echo "The image will be named opentrons-analysis:local" @echo "For a fresh build, run 'make local-build NO_CACHE=1'" - sed -i.bak '/^.git/s/^/#/' ../.dockerignore || true docker build $(BUILD_FLAGS) -t opentrons-analysis:local -f citools/Dockerfile.local .. || true - mv ../.dockerignore.bak ../.dockerignore || true @echo "Build complete" .PHONY: local-snapshot-test diff --git a/analyses-snapshot-testing/citools/Dockerfile.local b/analyses-snapshot-testing/citools/Dockerfile.local index 34e695e2c1f..d4acf845031 100644 --- a/analyses-snapshot-testing/citools/Dockerfile.local +++ b/analyses-snapshot-testing/citools/Dockerfile.local @@ -10,10 +10,9 @@ RUN apt-get update && \ WORKDIR /opentrons # Copy everything from the build context into the /opentrons directory +# root directory .dockerignore file is respected COPY . /opentrons -# List the contents of the /opentrons directory to verify the .git folder is copied -RUN ls -al /opentrons/.git # Install required packages from the copied code RUN python -m pip install -U ./shared-data/python From 768d5ce147017544b0ea75f4a0016a0265c5e116 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Wed, 6 Nov 2024 15:54:22 -0600 Subject: [PATCH 03/17] fixes and a cache --- .github/workflows/analyses-snapshot-test.yaml | 51 ++++++---- analyses-snapshot-testing/Makefile | 98 ++++++++++--------- .../{Dockerfile => Dockerfile.analyze} | 8 +- .../citools/Dockerfile.base | 7 ++ .../citools/Dockerfile.local | 9 +- .../citools/Dockerfile.server | 8 +- 6 files changed, 94 insertions(+), 87 deletions(-) rename analyses-snapshot-testing/citools/{Dockerfile => Dockerfile.analyze} (75%) create mode 100644 analyses-snapshot-testing/citools/Dockerfile.base diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index 09539d873e9..a9fb24bff76 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -45,12 +45,13 @@ jobs: timeout-minutes: 15 runs-on: ubuntu-latest env: + BASE_IMAGE_NAME: opentrons-python-base:3.10 ANALYSIS_REF: ${{ github.event.inputs.ANALYSIS_REF || github.head_ref || 'edge' }} SNAPSHOT_REF: ${{ github.event.inputs.SNAPSHOT_REF || github.head_ref || 'edge' }} # If we're running because of workflow_dispatch, use the user input to decide # whether to open a PR on failure. Otherwise, there is no user input, # so we only open a PR if the PR has the label 'gen-analyses-snapshot-pr' - OPEN_PR_ON_FAILURE: ${{ (github.event_name == 'workflow_dispatch' && github.events.inputs.OPEN_PR_ON_FAILURE) || ((github.event_name != 'workflow_dispatch') && (contains(github.event.pull_request.labels.*.name, 'gen-analyses-snapshot-pr'))) }} + OPEN_PR_ON_FAILURE: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.OPEN_PR_ON_FAILURE) || ((github.event_name != 'workflow_dispatch') && (contains(github.event.pull_request.labels.*.name, 'gen-analyses-snapshot-pr'))) }} PR_TARGET_BRANCH: ${{ github.event.pull_request.base.ref || 'not a pr'}} steps: - name: Checkout Repository @@ -58,22 +59,32 @@ jobs: with: ref: ${{ env.SNAPSHOT_REF }} - - name: Are the analyses snapshots in my PR branch in sync with the target branch? - if: github.event_name == 'pull_request' - run: | - git fetch origin ${{ env.PR_TARGET_BRANCH }} - DIFF_OUTPUT=$(git diff HEAD origin/${{ env.PR_TARGET_BRANCH }} -- analyses-snapshot-testing/tests/__snapshots__/analyses_snapshot_test) - if [ -n "$DIFF_OUTPUT" ]; then - echo "Analyses snapshots do NOT match ${{ env.PR_TARGET_BRANCH }} snapshots." - echo "Is this becasue you have not pulled and merged ${{ env.PR_TARGET_BRANCH }}?" - echo "Or is this because you have already updated your snapshots and are all good 😊?" - else - echo "Analyses snapshots match ${{ env.PR_TARGET_BRANCH }} snapshots." - fi - - - name: Docker Build + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Base Image Layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-base-cache + key: ${{ runner.os }}-docker-${{ env.BASE_IMAGE_NAME }} + restore-keys: | + ${{ runner.os }}-docker- + + - name: Build Base Docker Image with Makefile + working-directory: analyses-snapshot-testing + run: make build-base-image-ci + + - name: Cache Analysis Image Layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-analysis-cache + key: ${{ runner.os }}-docker-analysis-${{ env.ANALYSIS_REF }} + restore-keys: | + ${{ runner.os }}-docker-analysis- + + - name: Build Analysis Docker Image with Makefile working-directory: analyses-snapshot-testing - run: make build-opentrons-analysis + run: make build-opentrons-analysis-ci - name: Set up Python 3.13 uses: actions/setup-python@v5 @@ -112,8 +123,8 @@ jobs: commit-message: 'fix(analyses-snapshot-testing): heal analyses snapshots' title: 'fix(analyses-snapshot-testing): heal ${{ env.ANALYSIS_REF }} snapshots' body: 'This PR was requested on the PR https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}' - branch: 'analyses-snapshot-testing/${{ env.ANALYSIS_REF }}-from-${{ env.SNAPSHOT_REF}}' - base: ${{ env.SNAPSHOT_REF}} + branch: 'analyses-snapshot-testing/${{ env.ANALYSIS_REF }}-from-${{ env.SNAPSHOT_REF }}' + base: ${{ env.SNAPSHOT_REF }} - name: Comment on feature PR if: always() && steps.create_pull_request.outcome == 'success' && github.event_name == 'pull_request' @@ -135,5 +146,5 @@ jobs: commit-message: 'fix(analyses-snapshot-testing): heal ${{ env.ANALYSIS_REF }} snapshots' title: 'fix(analyses-snapshot-testing): heal ${{ env.ANALYSIS_REF }} snapshots' body: 'The ${{ env.ANALYSIS_REF }} overnight analyses snapshot test is failing. This PR was opened to alert us to the failure.' - branch: 'analyses-snapshot-testing/${{ env.ANALYSIS_REF }}-from-${{ env.SNAPSHOT_REF}}' - base: ${{ env.SNAPSHOT_REF}} + branch: 'analyses-snapshot-testing/${{ env.ANALYSIS_REF }}-from-${{ env.SNAPSHOT_REF }}' + base: ${{ env.SNAPSHOT_REF }} diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index a4f2a910e95..096a37e93ac 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -1,3 +1,15 @@ +BASE_IMAGE_NAME ?= opentrons-python-base:3.10 +CACHEBUST := $(shell date +%s) +ANALYSIS_REF ?= edge +PROTOCOL_NAMES ?= all +OVERRIDE_PROTOCOL_NAMES ?= all +OPENTRONS_VERSION ?= edge + +export OPENTRONS_VERSION # used for server +export ANALYSIS_REF # used for analysis and snapshot test +export PROTOCOL_NAMES # used for the snapshot test +export OVERRIDE_PROTOCOL_NAMES # used for the snapshot test + ifeq ($(CI), true) PYTHON=python else @@ -29,11 +41,11 @@ lint: black-check ruff-check mypy .PHONY: format format: - @echo runnning black + @echo "Running black" $(MAKE) black - @echo running ruff + @echo "Running ruff" $(MAKE) ruff - @echo formatting the readme with yarn prettier + @echo "Formatting the readme with yarn prettier" $(MAKE) format-readme .PHONY: test-ci @@ -54,20 +66,12 @@ teardown: .PHONY: format-readme format-readme: - yarn prettier --ignore-path .eslintignore --write analyses-snapshot-testing/**/*.md + yarn prettier --ignore-path .eslintignore --write analyses-snapshot-testing/**/*.md .github/workflows/analyses-snapshot-test.yaml .PHONY: install-pipenv install-pipenv: $(PYTHON) -m pip install -U pipenv -ANALYSIS_REF ?= edge -PROTOCOL_NAMES ?= all -OVERRIDE_PROTOCOL_NAMES ?= all - -export ANALYSIS_REF -export PROTOCOL_NAMES -export OVERRIDE_PROTOCOL_NAMES - .PHONY: snapshot-test snapshot-test: @echo "ANALYSIS_REF is $(ANALYSIS_REF)" @@ -82,30 +86,54 @@ snapshot-test-update: @echo "OVERRIDE_PROTOCOL_NAMES is $(OVERRIDE_PROTOCOL_NAMES)" $(PYTHON) -m pipenv run pytest -k analyses_snapshot_test --snapshot-update -CACHEBUST := $(shell date +%s) +.PHONY: build-base-image +build-base-image: + @echo "Building the base image $(BASE_IMAGE_NAME)" + docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/. + +.PHONY: build-base-image-ci +build-base-image-ci: + @echo "Building the base image $(BASE_IMAGE_NAME) with cache for CI" + docker build --cache-from type=local,src=/tmp/.buildx-base-cache \ + --cache-to type=local,dest=/tmp/.buildx-base-cache,mode=max \ + --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ + -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/. .PHONY: build-opentrons-analysis -build-opentrons-analysis: +build-opentrons-analysis: build-base-image @echo "Building docker image for $(ANALYSIS_REF)" @echo "The image will be named opentrons-analysis:$(ANALYSIS_REF)" @echo "If you want to build a different version, run 'make build-opentrons-analysis ANALYSIS_REF='" - @echo "Cache is always busted to ensure latest version of the code is used" - docker build --build-arg ANALYSIS_REF=$(ANALYSIS_REF) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-analysis:$(ANALYSIS_REF) citools/. + docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) --build-arg ANALYSIS_REF=$(ANALYSIS_REF) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. + +.PHONY: build-opentrons-analysis-ci +build-opentrons-analysis-ci: + @echo "Building docker image for $(ANALYSIS_REF) with cache for CI" + docker build --cache-from type=local,src=/tmp/.buildx-analysis-cache \ + --cache-to type=local,dest=/tmp/.buildx-analysis-cache,mode=max \ + --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ + --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ + --build-arg CACHEBUST=$(CACHEBUST) \ + -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. + +.PHONY: local-build +local-build: build-base-image + @echo "Building docker image for your local opentrons code" + @echo "The image will be named opentrons-analysis:local" + @echo "For a fresh build, run 'make local-build NO_CACHE=1'" + docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) $(BUILD_FLAGS) -t opentrons-analysis:local -f citools/Dockerfile.local .. || true + @echo "Build complete" .PHONY: generate-protocols generate-protocols: $(PYTHON) -m pipenv run python -m automation.data.protocol_registry - -OPENTRONS_VERSION ?= edge -export OPENTRONS_VERSION - .PHONY: build-rs -build-rs: +build-rs: build-base-image @echo "Building docker image for opentrons-robot-server:$(OPENTRONS_VERSION)" @echo "Cache is always busted to ensure latest version of the code is used" @echo "If you want to build a different version, run 'make build-rs OPENTRONS_VERSION=chore_release-8.0.0'" - docker build --build-arg OPENTRONS_VERSION=$(OPENTRONS_VERSION) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-robot-server:$(OPENTRONS_VERSION) -f citools/Dockerfile.server . + docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) --build-arg OPENTRONS_VERSION=$(OPENTRONS_VERSION) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-robot-server:$(OPENTRONS_VERSION) -f citools/Dockerfile.server . .PHONY: run-flex run-flex: @@ -118,29 +146,3 @@ run-ot2: @echo "Running opentrons-robot-server:$(OPENTRONS_VERSION)" @echo "If you want to run a different version, run 'make run-ot2 OPENTRONS_VERSION=chore_release-8.0.0'" docker run -p 31950:31950 --env-file ../robot-server/dev.env opentrons-robot-server:$(OPENTRONS_VERSION) - -BUILD_FLAGS := $(if $(NO_CACHE),--no-cache) - -.PHONY: local-build -local-build: - @echo "Building docker image for your local opentrons code" - @echo "The image will be named opentrons-analysis:local" - @echo "For a fresh build, run 'make local-build NO_CACHE=1'" - docker build $(BUILD_FLAGS) -t opentrons-analysis:local -f citools/Dockerfile.local .. || true - @echo "Build complete" - -.PHONY: local-snapshot-test -local-snapshot-test: - @echo "Running against local opentrons-analysis:local" - @echo "You must run this command like 'make local-snapshot-test ANALYSIS_REF=local'" - @echo "This is because the test suite reads the ANALYSIS_REF environment variable." - @echo "And uses it to determine which image to run against." - @echo "ANALYSIS_REF is $(ANALYSIS_REF)" - @if [ "$(ANALYSIS_REF)" = "local" ]; then \ - echo "ANALYSIS_REF is correctly set to 'local'"; \ - else \ - echo "Warning: ANALYSIS_REF is not set to 'local'"; \ - fi - @echo "PROTOCOL_NAMES is $(PROTOCOL_NAMES)" - @echo "OVERRIDE_PROTOCOL_NAMES is $(OVERRIDE_PROTOCOL_NAMES)" - $(PYTHON) -m pipenv run pytest -k analyses_snapshot_test -vv diff --git a/analyses-snapshot-testing/citools/Dockerfile b/analyses-snapshot-testing/citools/Dockerfile.analyze similarity index 75% rename from analyses-snapshot-testing/citools/Dockerfile rename to analyses-snapshot-testing/citools/Dockerfile.analyze index 123b7636652..1b85981cdaf 100644 --- a/analyses-snapshot-testing/citools/Dockerfile +++ b/analyses-snapshot-testing/citools/Dockerfile.analyze @@ -1,10 +1,6 @@ -# Use 3.10 just like the app does -FROM python:3.10-slim-bullseye +ARG BASE_IMAGE_NAME=opentrons-python-base:3.10 -# Update packages and install git -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y git libsystemd-dev +FROM ${BASE_IMAGE_NAME} # Define build arguments ARG ANALYSIS_REF=edge diff --git a/analyses-snapshot-testing/citools/Dockerfile.base b/analyses-snapshot-testing/citools/Dockerfile.base new file mode 100644 index 00000000000..086987e671b --- /dev/null +++ b/analyses-snapshot-testing/citools/Dockerfile.base @@ -0,0 +1,7 @@ +# Use Python 3.10 as the base image +FROM python:3.10-slim-bullseye + +# Update packages and install dependencies +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y git libsystemd-dev build-essential pkg-config network-manager diff --git a/analyses-snapshot-testing/citools/Dockerfile.local b/analyses-snapshot-testing/citools/Dockerfile.local index d4acf845031..2346b4680c2 100644 --- a/analyses-snapshot-testing/citools/Dockerfile.local +++ b/analyses-snapshot-testing/citools/Dockerfile.local @@ -1,10 +1,6 @@ -# Use Python 3.10, same as the app -FROM python:3.10-slim-bullseye +ARG BASE_IMAGE_NAME=opentrons-python-base:3.10 -# Update packages and install required dependencies -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y git libsystemd-dev +FROM ${BASE_IMAGE_NAME} # Set the working directory in the container WORKDIR /opentrons @@ -13,7 +9,6 @@ WORKDIR /opentrons # root directory .dockerignore file is respected COPY . /opentrons - # Install required packages from the copied code RUN python -m pip install -U ./shared-data/python RUN python -m pip install -U ./hardware[flex] diff --git a/analyses-snapshot-testing/citools/Dockerfile.server b/analyses-snapshot-testing/citools/Dockerfile.server index 6d4d9edcda3..0c44c1e04f0 100644 --- a/analyses-snapshot-testing/citools/Dockerfile.server +++ b/analyses-snapshot-testing/citools/Dockerfile.server @@ -1,10 +1,6 @@ -# Use Python 3.10 as the base image -FROM python:3.10-slim-bullseye +ARG BASE_IMAGE_NAME=opentrons-python-base:3.10 -# Update packages and install dependencies -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y git libsystemd-dev build-essential pkg-config network-manager +FROM ${BASE_IMAGE_NAME} # Define build arguments ARG OPENTRONS_VERSION=edge From 65604ca3005f1d33e74e1d8f249577f6dfef838c Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Wed, 6 Nov 2024 15:57:35 -0600 Subject: [PATCH 04/17] add back deletion --- .github/workflows/analyses-snapshot-test.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index a9fb24bff76..fdc0728776b 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -59,6 +59,19 @@ jobs: with: ref: ${{ env.SNAPSHOT_REF }} + - name: Are the analyses snapshots in my PR branch in sync with the target branch? + if: github.event_name == 'pull_request' + run: | + git fetch origin ${{ env.PR_TARGET_BRANCH }} + DIFF_OUTPUT=$(git diff HEAD origin/${{ env.PR_TARGET_BRANCH }} -- analyses-snapshot-testing/tests/__snapshots__/analyses_snapshot_test) + if [ -n "$DIFF_OUTPUT" ]; then + echo "Analyses snapshots do NOT match ${{ env.PR_TARGET_BRANCH }} snapshots." + echo "Is this becasue you have not pulled and merged ${{ env.PR_TARGET_BRANCH }}?" + echo "Or is this because you have already updated your snapshots and are all good 😊?" + else + echo "Analyses snapshots match ${{ env.PR_TARGET_BRANCH }} snapshots." + fi + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 From 4fe91a2dc9d223a9abbe95d24d50f47adb78cce6 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Wed, 6 Nov 2024 16:09:37 -0600 Subject: [PATCH 05/17] add buildx to the command --- analyses-snapshot-testing/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index 096a37e93ac..49475e5d2d4 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -94,10 +94,10 @@ build-base-image: .PHONY: build-base-image-ci build-base-image-ci: @echo "Building the base image $(BASE_IMAGE_NAME) with cache for CI" - docker build --cache-from type=local,src=/tmp/.buildx-base-cache \ + docker buildx build --cache-from type=local,src=/tmp/.buildx-base-cache \ --cache-to type=local,dest=/tmp/.buildx-base-cache,mode=max \ --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ - -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/. + -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/. --load .PHONY: build-opentrons-analysis build-opentrons-analysis: build-base-image @@ -109,12 +109,12 @@ build-opentrons-analysis: build-base-image .PHONY: build-opentrons-analysis-ci build-opentrons-analysis-ci: @echo "Building docker image for $(ANALYSIS_REF) with cache for CI" - docker build --cache-from type=local,src=/tmp/.buildx-analysis-cache \ + docker buildx build --cache-from type=local,src=/tmp/.buildx-analysis-cache \ --cache-to type=local,dest=/tmp/.buildx-analysis-cache,mode=max \ --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ --build-arg CACHEBUST=$(CACHEBUST) \ - -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. + -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. --load .PHONY: local-build local-build: build-base-image From ffbaab7bd2d7d723c042b33003d41561acc892a6 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Wed, 6 Nov 2024 16:15:20 -0600 Subject: [PATCH 06/17] local son --- analyses-snapshot-testing/Makefile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index 49475e5d2d4..20c576f73ff 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -95,9 +95,10 @@ build-base-image: build-base-image-ci: @echo "Building the base image $(BASE_IMAGE_NAME) with cache for CI" docker buildx build --cache-from type=local,src=/tmp/.buildx-base-cache \ - --cache-to type=local,dest=/tmp/.buildx-base-cache,mode=max \ - --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ - -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/. --load + --cache-to type=local,dest=/tmp/.buildx-base-cache,mode=max \ + --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ + -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/ --load + .PHONY: build-opentrons-analysis build-opentrons-analysis: build-base-image @@ -110,11 +111,12 @@ build-opentrons-analysis: build-base-image build-opentrons-analysis-ci: @echo "Building docker image for $(ANALYSIS_REF) with cache for CI" docker buildx build --cache-from type=local,src=/tmp/.buildx-analysis-cache \ - --cache-to type=local,dest=/tmp/.buildx-analysis-cache,mode=max \ - --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ - --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ - --build-arg CACHEBUST=$(CACHEBUST) \ - -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. --load + --cache-to type=local,dest=/tmp/.buildx-analysis-cache,mode=max \ + --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ + --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ + --build-arg CACHEBUST=$(CACHEBUST) \ + -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/ --load + .PHONY: local-build local-build: build-base-image From 58d1c17f885dc6b338917afb01d16578df75b3e9 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Wed, 6 Nov 2024 16:22:24 -0600 Subject: [PATCH 07/17] one cache --- .github/workflows/analyses-snapshot-test.yaml | 16 ++-------------- analyses-snapshot-testing/Makefile | 10 +++++----- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index fdc0728776b..f9ec64f0290 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -78,24 +78,12 @@ jobs: - name: Cache Base Image Layers uses: actions/cache@v4 with: - path: /tmp/.buildx-base-cache + path: /tmp/.buildx-cache key: ${{ runner.os }}-docker-${{ env.BASE_IMAGE_NAME }} restore-keys: | ${{ runner.os }}-docker- - - name: Build Base Docker Image with Makefile - working-directory: analyses-snapshot-testing - run: make build-base-image-ci - - - name: Cache Analysis Image Layers - uses: actions/cache@v4 - with: - path: /tmp/.buildx-analysis-cache - key: ${{ runner.os }}-docker-analysis-${{ env.ANALYSIS_REF }} - restore-keys: | - ${{ runner.os }}-docker-analysis- - - - name: Build Analysis Docker Image with Makefile + - name: Build Images with Makefile working-directory: analyses-snapshot-testing run: make build-opentrons-analysis-ci diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index 20c576f73ff..0a82312c07e 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -94,8 +94,8 @@ build-base-image: .PHONY: build-base-image-ci build-base-image-ci: @echo "Building the base image $(BASE_IMAGE_NAME) with cache for CI" - docker buildx build --cache-from type=local,src=/tmp/.buildx-base-cache \ - --cache-to type=local,dest=/tmp/.buildx-base-cache,mode=max \ + docker buildx build --cache-from type=local,src=/tmp/.buildx-cache \ + --cache-to type=local,dest=/tmp/.buildx-cache,mode=max \ --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/ --load @@ -108,10 +108,10 @@ build-opentrons-analysis: build-base-image docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) --build-arg ANALYSIS_REF=$(ANALYSIS_REF) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. .PHONY: build-opentrons-analysis-ci -build-opentrons-analysis-ci: +build-opentrons-analysis-ci: build-base-image-ci @echo "Building docker image for $(ANALYSIS_REF) with cache for CI" - docker buildx build --cache-from type=local,src=/tmp/.buildx-analysis-cache \ - --cache-to type=local,dest=/tmp/.buildx-analysis-cache,mode=max \ + docker buildx build --cache-from type=local,src=/tmp/.buildx-cache \ + --cache-to type=local,dest=/tmp/.buildx-cache,mode=max \ --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ --build-arg CACHEBUST=$(CACHEBUST) \ From deffc3fb6c92fcbf3db19403451b5b04fa3871ad Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Wed, 6 Nov 2024 16:31:51 -0600 Subject: [PATCH 08/17] cleaner --- .github/workflows/analyses-snapshot-test.yaml | 5 ++- analyses-snapshot-testing/Makefile | 38 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index f9ec64f0290..abecf98f3d9 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -46,6 +46,7 @@ jobs: runs-on: ubuntu-latest env: BASE_IMAGE_NAME: opentrons-python-base:3.10 + CACHE_DIR: /tmp/.buildx-cache ANALYSIS_REF: ${{ github.event.inputs.ANALYSIS_REF || github.head_ref || 'edge' }} SNAPSHOT_REF: ${{ github.event.inputs.SNAPSHOT_REF || github.head_ref || 'edge' }} # If we're running because of workflow_dispatch, use the user input to decide @@ -78,14 +79,14 @@ jobs: - name: Cache Base Image Layers uses: actions/cache@v4 with: - path: /tmp/.buildx-cache + path: ${{ env.CACHE_DIR }} key: ${{ runner.os }}-docker-${{ env.BASE_IMAGE_NAME }} restore-keys: | ${{ runner.os }}-docker- - name: Build Images with Makefile working-directory: analyses-snapshot-testing - run: make build-opentrons-analysis-ci + run: make build-all-ci - name: Set up Python 3.13 uses: actions/setup-python@v5 diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index 0a82312c07e..8d763c2a16e 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -4,6 +4,7 @@ ANALYSIS_REF ?= edge PROTOCOL_NAMES ?= all OVERRIDE_PROTOCOL_NAMES ?= all OPENTRONS_VERSION ?= edge +CACHE_DIR := /tmp/.buildx-cache export OPENTRONS_VERSION # used for server export ANALYSIS_REF # used for analysis and snapshot test @@ -91,15 +92,6 @@ build-base-image: @echo "Building the base image $(BASE_IMAGE_NAME)" docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/. -.PHONY: build-base-image-ci -build-base-image-ci: - @echo "Building the base image $(BASE_IMAGE_NAME) with cache for CI" - docker buildx build --cache-from type=local,src=/tmp/.buildx-cache \ - --cache-to type=local,dest=/tmp/.buildx-cache,mode=max \ - --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ - -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/ --load - - .PHONY: build-opentrons-analysis build-opentrons-analysis: build-base-image @echo "Building docker image for $(ANALYSIS_REF)" @@ -107,15 +99,29 @@ build-opentrons-analysis: build-base-image @echo "If you want to build a different version, run 'make build-opentrons-analysis ANALYSIS_REF='" docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) --build-arg ANALYSIS_REF=$(ANALYSIS_REF) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. + + +.PHONY: build-base-image-ci +build-base-image-ci: + @echo "Building the base image $(BASE_IMAGE_NAME) with cache for CI" + docker buildx build --cache-from type=local,src=$(CACHE_DIR) \ + --cache-to type=local,dest=$(CACHE_DIR),mode=max \ + --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ + -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/ --output=type=docker + .PHONY: build-opentrons-analysis-ci -build-opentrons-analysis-ci: build-base-image-ci +build-opentrons-analysis-ci: @echo "Building docker image for $(ANALYSIS_REF) with cache for CI" - docker buildx build --cache-from type=local,src=/tmp/.buildx-cache \ - --cache-to type=local,dest=/tmp/.buildx-cache,mode=max \ - --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ - --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ - --build-arg CACHEBUST=$(CACHEBUST) \ - -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/ --load + docker buildx build --cache-from type=local,src=$(CACHE_DIR) \ + --cache-to type=local,dest=$(CACHE_DIR),mode=max \ + --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ + --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ + --build-arg CACHEBUST=$(CACHEBUST) \ + -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/ --output=type=docker + +.PHONY: build-all-ci +build-all-ci: build-base-image-ci build-opentrons-analysis-ci + @echo "Built both base and analysis images with shared cache" .PHONY: local-build From f4931d526ea02e15bf0e947e097213a203c83eaf Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 09:01:11 -0600 Subject: [PATCH 09/17] use build and push action --- analyses-snapshot-testing/Makefile | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index 8d763c2a16e..1a2cc763e5d 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -99,31 +99,6 @@ build-opentrons-analysis: build-base-image @echo "If you want to build a different version, run 'make build-opentrons-analysis ANALYSIS_REF='" docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) --build-arg ANALYSIS_REF=$(ANALYSIS_REF) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. - - -.PHONY: build-base-image-ci -build-base-image-ci: - @echo "Building the base image $(BASE_IMAGE_NAME) with cache for CI" - docker buildx build --cache-from type=local,src=$(CACHE_DIR) \ - --cache-to type=local,dest=$(CACHE_DIR),mode=max \ - --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ - -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/ --output=type=docker - -.PHONY: build-opentrons-analysis-ci -build-opentrons-analysis-ci: - @echo "Building docker image for $(ANALYSIS_REF) with cache for CI" - docker buildx build --cache-from type=local,src=$(CACHE_DIR) \ - --cache-to type=local,dest=$(CACHE_DIR),mode=max \ - --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) \ - --build-arg ANALYSIS_REF=$(ANALYSIS_REF) \ - --build-arg CACHEBUST=$(CACHEBUST) \ - -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/ --output=type=docker - -.PHONY: build-all-ci -build-all-ci: build-base-image-ci build-opentrons-analysis-ci - @echo "Built both base and analysis images with shared cache" - - .PHONY: local-build local-build: build-base-image @echo "Building docker image for your local opentrons code" From b4d82bdc8c9058c8436c2079b79ec4f761e65878 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 09:01:48 -0600 Subject: [PATCH 10/17] use build and push action2 --- .github/workflows/analyses-snapshot-test.yaml | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index abecf98f3d9..06dac2e8def 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -46,7 +46,6 @@ jobs: runs-on: ubuntu-latest env: BASE_IMAGE_NAME: opentrons-python-base:3.10 - CACHE_DIR: /tmp/.buildx-cache ANALYSIS_REF: ${{ github.event.inputs.ANALYSIS_REF || github.head_ref || 'edge' }} SNAPSHOT_REF: ${{ github.event.inputs.SNAPSHOT_REF || github.head_ref || 'edge' }} # If we're running because of workflow_dispatch, use the user input to decide @@ -76,17 +75,31 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Cache Base Image Layers - uses: actions/cache@v4 + - name: Build and push base image + uses: docker/build-push-action@v6 with: - path: ${{ env.CACHE_DIR }} - key: ${{ runner.os }}-docker-${{ env.BASE_IMAGE_NAME }} - restore-keys: | - ${{ runner.os }}-docker- - - - name: Build Images with Makefile - working-directory: analyses-snapshot-testing - run: make build-all-ci + context: ./citools + file: ./citools/Dockerfile.base + push: false + load: true + tags: ${{ env.BASE_IMAGE_NAME }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build analysis image + uses: docker/build-push-action@v6 + with: + context: ./citools + file: ./citools/Dockerfile.analyze + push: false + load: true + tags: opentrons-analysis:${{ env.ANALYSIS_REF }} # Name the image for local use + build-args: | + BASE_IMAGE_NAME=${{ env.BASE_IMAGE_NAME }} + ANALYSIS_REF=${{ env.ANALYSIS_REF }} + CACHEBUST=$(date +%s) # Always clone the latest code + cache-from: type=gha + cache-to: type=gha,mode=max - name: Set up Python 3.13 uses: actions/setup-python@v5 From 540d9ffeef8d09c2007c84cd2b36094eedeb98cf Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 09:18:15 -0600 Subject: [PATCH 11/17] fix context and file path --- .github/workflows/analyses-snapshot-test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index 06dac2e8def..0d63619e909 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -78,8 +78,8 @@ jobs: - name: Build and push base image uses: docker/build-push-action@v6 with: - context: ./citools - file: ./citools/Dockerfile.base + context: analyses-snapshot-testing/citools + file: analyses-snapshot-testing/citools/Dockerfile.base push: false load: true tags: ${{ env.BASE_IMAGE_NAME }} @@ -89,8 +89,8 @@ jobs: - name: Build analysis image uses: docker/build-push-action@v6 with: - context: ./citools - file: ./citools/Dockerfile.analyze + context: analyses-snapshot-testing/citools + file: analyses-snapshot-testing/citools/Dockerfile.analyze push: false load: true tags: opentrons-analysis:${{ env.ANALYSIS_REF }} # Name the image for local use From 3a1172c6ca0e0a459979b39bbfadb042be9fd03d Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 09:39:44 -0600 Subject: [PATCH 12/17] imageid --- .github/workflows/analyses-snapshot-test.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index 0d63619e909..f19c83b326e 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -75,7 +75,8 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build and push base image + - name: Build base image + id: build_base_image uses: docker/build-push-action@v6 with: context: analyses-snapshot-testing/citools @@ -93,11 +94,11 @@ jobs: file: analyses-snapshot-testing/citools/Dockerfile.analyze push: false load: true - tags: opentrons-analysis:${{ env.ANALYSIS_REF }} # Name the image for local use + tags: opentrons-analysis:${{ env.ANALYSIS_REF }} build-args: | - BASE_IMAGE_NAME=${{ env.BASE_IMAGE_NAME }} + BASE_IMAGE_NAME=${{ steps.build_base_image.outputs.imageid }} ANALYSIS_REF=${{ env.ANALYSIS_REF }} - CACHEBUST=$(date +%s) # Always clone the latest code + CACHEBUST=$(date +%s) cache-from: type=gha cache-to: type=gha,mode=max From 139b9c0c37c7463044b8bdee516734ead1ab4a54 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 09:47:18 -0600 Subject: [PATCH 13/17] list images --- .github/workflows/analyses-snapshot-test.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index f19c83b326e..4ab68443da5 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -87,6 +87,12 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max + - name: List docker images + run: docker images + + - name: List buildx images + run: docker buildx images + - name: Build analysis image uses: docker/build-push-action@v6 with: @@ -96,7 +102,7 @@ jobs: load: true tags: opentrons-analysis:${{ env.ANALYSIS_REF }} build-args: | - BASE_IMAGE_NAME=${{ steps.build_base_image.outputs.imageid }} + BASE_IMAGE_NAME=${{ env.BASE_IMAGE_NAME }} ANALYSIS_REF=${{ env.ANALYSIS_REF }} CACHEBUST=$(date +%s) cache-from: type=gha From 7500bc2f46ddc3ae5034557f3645e63d9429ab87 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 09:54:01 -0600 Subject: [PATCH 14/17] ug --- .github/workflows/analyses-snapshot-test.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index 4ab68443da5..238a97875f7 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -90,9 +90,6 @@ jobs: - name: List docker images run: docker images - - name: List buildx images - run: docker buildx images - - name: Build analysis image uses: docker/build-push-action@v6 with: From 387ec824225b22b835c46078549be52079cb9b62 Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 10:23:05 -0600 Subject: [PATCH 15/17] use docker for the second build --- .github/workflows/analyses-snapshot-test.yaml | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/.github/workflows/analyses-snapshot-test.yaml b/.github/workflows/analyses-snapshot-test.yaml index 238a97875f7..fffdd6b667d 100644 --- a/.github/workflows/analyses-snapshot-test.yaml +++ b/.github/workflows/analyses-snapshot-test.yaml @@ -87,23 +87,9 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - - name: List docker images - run: docker images - - name: Build analysis image - uses: docker/build-push-action@v6 - with: - context: analyses-snapshot-testing/citools - file: analyses-snapshot-testing/citools/Dockerfile.analyze - push: false - load: true - tags: opentrons-analysis:${{ env.ANALYSIS_REF }} - build-args: | - BASE_IMAGE_NAME=${{ env.BASE_IMAGE_NAME }} - ANALYSIS_REF=${{ env.ANALYSIS_REF }} - CACHEBUST=$(date +%s) - cache-from: type=gha - cache-to: type=gha,mode=max + working-directory: analyses-snapshot-testing + run: make build-opentrons-analysis BASE_IMAGE_NAME=${{ env.BASE_IMAGE_NAME }} ANALYSIS_REF=${{ env.ANALYSIS_REF }} CACHEBUST=${{ github.run_number }} - name: Set up Python 3.13 uses: actions/setup-python@v5 From a3858c214087f6be4138c21d4d7a45fa206d83aa Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 10:32:49 -0600 Subject: [PATCH 16/17] remove base build from make targets --- analyses-snapshot-testing/Makefile | 6 +++--- analyses-snapshot-testing/README.md | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index 1a2cc763e5d..42e4781d058 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -93,14 +93,14 @@ build-base-image: docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) -f citools/Dockerfile.base -t $(BASE_IMAGE_NAME) citools/. .PHONY: build-opentrons-analysis -build-opentrons-analysis: build-base-image +build-opentrons-analysis: @echo "Building docker image for $(ANALYSIS_REF)" @echo "The image will be named opentrons-analysis:$(ANALYSIS_REF)" @echo "If you want to build a different version, run 'make build-opentrons-analysis ANALYSIS_REF='" docker build --build-arg BASE_IMAGE_NAME=$(BASE_IMAGE_NAME) --build-arg ANALYSIS_REF=$(ANALYSIS_REF) --build-arg CACHEBUST=$(CACHEBUST) -t opentrons-analysis:$(ANALYSIS_REF) -f citools/Dockerfile.analyze citools/. .PHONY: local-build -local-build: build-base-image +local-build: @echo "Building docker image for your local opentrons code" @echo "The image will be named opentrons-analysis:local" @echo "For a fresh build, run 'make local-build NO_CACHE=1'" @@ -112,7 +112,7 @@ generate-protocols: $(PYTHON) -m pipenv run python -m automation.data.protocol_registry .PHONY: build-rs -build-rs: build-base-image +build-rs: @echo "Building docker image for opentrons-robot-server:$(OPENTRONS_VERSION)" @echo "Cache is always busted to ensure latest version of the code is used" @echo "If you want to build a different version, run 'make build-rs OPENTRONS_VERSION=chore_release-8.0.0'" diff --git a/analyses-snapshot-testing/README.md b/analyses-snapshot-testing/README.md index cd9a230bc16..78423b8447f 100644 --- a/analyses-snapshot-testing/README.md +++ b/analyses-snapshot-testing/README.md @@ -18,7 +18,10 @@ > This ALWAYS gets the remote code pushed to Opentrons/opentrons for the specified ANALYSIS_REF -`make build-opentrons-analysis ANALYSIS_REF=chore_release-8.0.0` +- build the base image + - `make build-base-image` +- build the opentrons-analysis image + - `make build-opentrons-analysis ANALYSIS_REF=release` ## Running the tests locally @@ -51,16 +54,25 @@ ```shell cd analyses-snapshot-testing \ -&& make build-rs OPENTRONS_VERSION=chore_release-8.0.0 \ -&& make run-rs OPENTRONS_VERSION=chore_release-8.0.0` +&& make build-base-image \ +&& make build-rs OPENTRONS_VERSION=release \ +&& make run-rs OPENTRONS_VERSION=release` ``` ### Default OPENTRONS_VERSION=edge in the Makefile so you can omit it if you want latest edge -`cd analyses-snapshot-testing && make build-rs && make run-rs` +```shell +cd analyses-snapshot-testing \ +&& make build-base-image \ +&& make build-rs \ +&& make run-rs +``` ## Running the Analyses Battery against your local code +> This copies in your local code to the container and runs the analyses battery against it. + +1. `make build-base-image` 1. `make build-local` 1. `make local-snapshot-test` From 4f9b8c9d75c01eda590cd65c5a3da39470a28a6f Mon Sep 17 00:00:00 2001 From: Josh McVey Date: Thu, 7 Nov 2024 10:52:12 -0600 Subject: [PATCH 17/17] final cleanup --- analyses-snapshot-testing/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/analyses-snapshot-testing/Makefile b/analyses-snapshot-testing/Makefile index 42e4781d058..de5e0381131 100644 --- a/analyses-snapshot-testing/Makefile +++ b/analyses-snapshot-testing/Makefile @@ -1,10 +1,9 @@ BASE_IMAGE_NAME ?= opentrons-python-base:3.10 -CACHEBUST := $(shell date +%s) +CACHEBUST ?= $(shell date +%s) ANALYSIS_REF ?= edge PROTOCOL_NAMES ?= all OVERRIDE_PROTOCOL_NAMES ?= all OPENTRONS_VERSION ?= edge -CACHE_DIR := /tmp/.buildx-cache export OPENTRONS_VERSION # used for server export ANALYSIS_REF # used for analysis and snapshot test