From a61bc075fdc24cb7f932f3723912824532b42ea3 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 22 Nov 2020 23:34:12 +0100 Subject: [PATCH] feat: Container based developer flow (#258) Co-authored-by: CrazyMax --- .dockerignore | 1 + .github/workflows/pre-checkin.yml | 30 ----------------- .github/workflows/test.yml | 15 +++++++++ Dockerfile.dev | 46 +++++++++++++++++++++++++++ README.md | 14 ++++++++ docker-bake.hcl | 53 +++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 30 deletions(-) create mode 100644 .dockerignore delete mode 100644 .github/workflows/pre-checkin.yml create mode 100644 Dockerfile.dev create mode 100644 docker-bake.hcl diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/.github/workflows/pre-checkin.yml b/.github/workflows/pre-checkin.yml deleted file mode 100644 index 38808c1..0000000 --- a/.github/workflows/pre-checkin.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: pre-checkin - -on: - push: - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' - -jobs: - pre-checkin: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Install - run: yarn install - - - name: Pre-checkin - run: yarn run pre-checkin - - - name: Check for uncommitted changes - run: | - if [[ `git status --porcelain` ]]; then - git status --porcelain - echo "::warning::Found changes. Please run 'yarn run pre-checkin' and push" - fi diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b98b7ec..560a115 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,21 @@ on: - '**.md' jobs: + test-containerized: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - + name: Validate + run: docker buildx bake validate + - + name: Test + run: docker buildx bake test + test: runs-on: ${{ matrix.os }} strategy: diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..d9c66e4 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,46 @@ +#syntax=docker/dockerfile:1.1-experimental + +FROM node:12 AS deps +WORKDIR /src +COPY package.json yarn.lock ./ +RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \ + yarn install + +FROM scratch AS update-yarn +COPY --from=deps /src/yarn.lock / + +FROM deps AS validate-yarn +COPY .git .git +RUN status=$(git status --porcelain -- yarn.lock); if [ -n "$status" ]; then echo $status; exit 1; fi + +FROM deps AS base +COPY . . + +FROM base AS build +RUN yarn build + +FROM deps AS test +ARG TARGETOS +ARG TARGETARCH +ENV RUNNER_TEMP=/tmp/github_runner +ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache +COPY . . +RUN yarn run test + +FROM base AS run-format +RUN yarn run format + +FROM scratch AS format +COPY --from=run-format /src/src/*.ts /src/ + +FROM base AS validate-format +RUN yarn run format-check + +FROM scratch AS dist +COPY --from=build /src/dist/ /dist/ + +FROM build AS validate-build +RUN status=$(git status --porcelain -- dist); if [ -n "$status" ]; then echo $status; exit 1; fi + +FROM base AS dev +ENTRYPOINT ["bash"] diff --git a/README.md b/README.md index 7a93582..fad58fd 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ ___ * [inputs](#inputs) * [environment variables](#environment-variables) * [Limitation](#limitation) +* [Development](#development) * [License](#license) ## Usage @@ -178,6 +179,19 @@ secret named `GH_PAT`, the step will look like this: GITHUB_TOKEN: ${{ secrets.GH_PAT }} ``` +## Development + +``` +# format code and build javascript artifacts +docker buildx bake pre-checkin + +# validate all code has correctly formatted and built +docker buildx bake validate + +# run tests +docker buildx bake test +``` + ## License MIT. See `LICENSE` for more details. diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..8cf6a60 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,53 @@ +group "default" { + targets = ["build"] +} + +group "pre-checkin" { + targets = ["update-yarn", "format", "build"] +} + +group "validate" { + targets = ["validate-format", "validate-build", "validate-yarn"] +} + +target "dockerfile" { + dockerfile = "Dockerfile.dev" +} + +target "update-yarn" { + inherits = ["dockerfile"] + target = "update-yarn" + output = ["."] +} + +target "build" { + inherits = ["dockerfile"] + target = "dist" + output = ["."] +} + +target "test" { + inherits = ["dockerfile"] + target = "test" +} + +target "format" { + inherits = ["dockerfile"] + target = "format" + output = ["."] +} + +target "validate-format" { + inherits = ["dockerfile"] + target = "validate-format" +} + +target "validate-build" { + inherits = ["dockerfile"] + target = "validate-build" +} + +target "validate-yarn" { + inherits = ["dockerfile"] + target = "validate-yarn" +}