-
-
Save rmadhiapplitools/6c343c4e25b86a91bea62dde956cfc7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Docker file is based on example Cypress E2E tests created by glebbahmutov | |
#https://github.com/bahmutov/google-cloud-build-example | |
# multi-stage Docker build with testing node_modules and Cypress binary | |
# discarded before serving in production | |
# https://glebbahmutov.com/blog/making-small-docker-image/ | |
# testing image - we really want to cache AS MUCH AS POSSIBLE | |
# so we build like this | |
# - copy package files | |
# - run "npm ci" | |
# - copy spec files | |
# this way Cypress and node_modules are cached as long as package files stay same | |
# Docker build looks at the file checksums during each "COPY ..." command | |
# and if the copied files were the same, the image layer is cached and not recomputed | |
# https://docs.docker.com/v17.09/engine/userguide/eng-image/dockerfile_best-practices/#build-cache | |
# every other command like "RUN npm ci" is cached by default unless the command itself has been changed | |
FROM cypress/base:10 as TEST | |
WORKDIR / | |
# dependencies will be installed only if the package files change | |
COPY package.json . | |
COPY package-lock.json . | |
# by setting CI environment variable we switch the Cypress install messages | |
# to small "started / finished" and avoid 1000s of lines of progress messages | |
# https://github.com/cypress-io/cypress/issues/1243 | |
ENV CI=1 | |
RUN npm ci | |
# tests will rerun if the "cypress" folder, "cypress.json" file or "public" folder | |
# has any changes | |
# copy tests | |
COPY cypress cypress | |
COPY cypress.json . | |
COPY applitools.config.js . | |
# copy what to test | |
# to avoid Docker thinking it is the same command and skipping tests | |
# have a dummy command here | |
# see discussion in https://github.com/moby/moby/issues/1996 | |
# find variable that changes. For example on Zeit.co Now GitHub deploys the HOSTNAME changes | |
# RUN env | |
ARG HOSTNAME=1 | |
ARG COMMIT_ID=$COMMIT_SHA | |
ARG Git_branch=$BRANCH_NAME | |
# if you run "docker build . --build-arg HOSTNAME=foo" | |
# it will bust this cache and it will rerun all commands from here | |
#Configure your applitools api key by setting it as ENV variable below or access it fromm secrets | |
ENV APPLITOOLS_API_KEY #INSERTKEY VALUE | |
RUN echo $APPLITOOLS_API_KEY | |
ENV APPLITOOLS_BATCH_ID=$COMMIT_ID | |
ENV APPLITOOLS_BRANCH_NAME=$Git_branch | |
RUN echo $APPLITOOLS_BATCH_ID | |
RUN echo $APPLITOOLS_API_KEY | |
RUN ls -la | |
RUN ./node_modules/cypress/bin/cypress run --spec "cypress/integration/examples/applitools.spec.js" | |
#RUN npm test | |
# RUN apt-get update && apt-get install -y \ | |
# curl | |
RUN echo $APPLITOOLS_BATCH_ID | |
RUN echo $APPLITOOLS_API_KEY | |
RUN curl -d '' -X POST https://eyesapi.applitools.com/api/externals/github/servers/github.com/commit/$APPLITOOLS_BATCH_ID/complete?apiKey=$APPLITOOLS_API_KEY | |
#Reports applitools build status | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment