From 48907467804e0dd23e032aaad79db58704bd4329 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 13 Feb 2021 12:02:44 +0100 Subject: [PATCH] Container based developer flow Signed-off-by: CrazyMax --- .dockerignore | 4 +++ .github/CONTRIBUTING.md | 13 +++++++++ .github/workflows/validate.yml | 25 ++++++++++++++++ Dockerfile.dev | 41 +++++++++++++++++++++++++++ docker-bake.hcl | 52 ++++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/validate.yml create mode 100644 Dockerfile.dev create mode 100644 docker-bake.hcl diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..00a9f54 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +/.dev +/dist +/lib +/node_modules diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 941be96..4afc81e 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -14,6 +14,19 @@ Contributions to this project are [released](https://help.github.com/articles/gi 7. Push to your fork and [submit a pull request](https://github.com/docker/setup-qemu-action/compare) 8. Pat your self on the back and wait for your pull request to be reviewed and merged. +## Container based developer flow + +If you don't want to maintain a Node developer environment that fits this project you can use containerized commands +instead of invoking yarn directly. + +``` +# format code and build javascript artifacts +docker buildx bake pre-checkin + +# validate all code has correctly formatted and built +docker buildx bake validate +``` + Here are a few things you can do that will increase the likelihood of your pull request being accepted: - Make sure the `README.md` and any other relevant **documentation are kept up-to-date**. diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..0134e68 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,25 @@ +name: validate + +on: + push: + branches: + - 'master' + - 'releases/v*' + paths-ignore: + - '**.md' + pull_request: + branches: + - 'master' + paths-ignore: + - '**.md' + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Validate + run: docker buildx bake validate diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..c6e16ae --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,41 @@ +#syntax=docker/dockerfile:1.2 + +FROM node:12 AS deps +WORKDIR /src +COPY package.json yarn.lock ./ +RUN --mount=type=cache,target=/src/node_modules \ + 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 --mount=type=cache,target=/src/node_modules \ + yarn build + +FROM base AS run-format +RUN --mount=type=cache,target=/src/node_modules \ + yarn run format + +FROM scratch AS format +COPY --from=run-format /src/src/*.ts /src/ + +FROM base AS validate-format +RUN --mount=type=cache,target=/src/node_modules \ + 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/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..ab8b042 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,52 @@ +variable "GITHUB_REPOSITORY" { + default = "docker/setup-qemu-action" +} + +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 "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" +}