From 95e8d81fa3b52ae5125266093715e59c922bc99d Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Fri, 14 Aug 2020 18:26:39 +0200 Subject: [PATCH] Containerize proto generation and test Signed-off-by: Chris Crone --- .dockerignore | 1 + Dockerfile | 18 ++++++++++++++---- Makefile | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 Makefile diff --git a/.dockerignore b/.dockerignore index 651665b..7904710 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ node_modules .git +Makefile diff --git a/Dockerfile b/Dockerfile index 4d82b3c..63e4601 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # syntax = docker/dockerfile:experimental -FROM node:12-alpine as base +FROM node:12-buster-slim AS base +WORKDIR /src ARG DOCKER_GITHUB_TOKEN ENV DOCKER_GITHUB_TOKEN=${DOCKER_GITHUB_TOKEN} COPY package.json . @@ -10,6 +11,15 @@ RUN --mount=type=cache,target=/usr/local/share/.cache/yarn/v6 \ COPY . . -RUN yarn download-cli && \ - chmod +x docker-linux-amd64 && \ - yarn test +FROM base AS test +CMD ["yarn", "test"] +VOLUME ["/var/run/docker.sock"] +COPY --from=docker /usr/local/bin/docker /usr/local/bin/com.docker.cli +RUN yarn download-cli + +FROM base AS download-protos +RUN yarn download-protos +RUN ./protos.sh + +FROM scratch AS protos +COPY --from=download-protos /src/src / diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9786b2a --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +ifeq (${DOCKER_GITHUB_TOKEN},) + @echo "DOCKER_GITHUB_TOKEN empty + @echo "Set with a GitHub token that has access to docker/compose-cli" + exit 1 +endif + +IMG?=node-sdk-test + +all: test + +.PHONY: test +test: + @docker build --target test --tag ${IMG} --build-arg DOCKER_GITHUB_TOKEN . + docker run --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + ${IMG} + +.PHONY: protos +protos: + @docker build --target protos --build-arg DOCKER_GITHUB_TOKEN --output ./src .