Container based developer flow

This commit is contained in:
CrazyMax
2020-12-19 03:21:31 +01:00
parent adc72eac06
commit 2654df7d45
7 changed files with 1051 additions and 49 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
/.dev
/coverage
/dist
/lib
/node_modules
/.env

View File

@ -7,13 +7,14 @@ Contributions to this project are [released](https://help.github.com/articles/gi
## Submitting a pull request
1. [Fork](https://github.com/crazy-max/ghaction-docker-buildx-bake/fork) and clone the repository
2. Configure and install the dependencies: `yarn install`
2. Configure and install the dependencies locally: `yarn install`
3. Make sure the tests pass on your machine: `yarn run test`
4. Create a new branch: `git checkout -b my-branch-name`
5. Make your change, add tests, and make sure the tests still pass
6. Run pre-checkin: `yarn run pre-checkin`
7. Push to your fork and [submit a pull request](https://github.com/crazy-max/ghaction-docker-buildx-bake/compare)
8. Pat your self on the back and wait for your pull request to be reviewed and merged.
5. Make your changes, add tests, and make sure the tests still pass
6. Format code and build javascript artifacts: `docker buildx bake pre-checkin`
7. Validate all code has correctly formatted and built: `docker buildx bake validate`
8. Push to your fork and [submit a pull request](https://github.com/crazy-max/ghaction-docker-buildx-bake/compare)
9. Pat your self on the back and wait for your pull request to be reviewed and merged.
Here are a few things you can do that will increase the likelihood of your pull request being accepted:

View File

@ -3,10 +3,15 @@ name: test
on:
push:
branches:
- master
- 'master'
- 'releases/v*'
paths-ignore:
- '**.md'
pull_request:
branches:
- master
- 'master'
paths-ignore:
- '**.md'
jobs:
test:
@ -15,16 +20,12 @@ jobs:
-
name: Checkout
uses: actions/checkout@v2
-
name: Install
run: yarn install
-
name: Test
run: yarn run test
run: docker buildx bake test
-
name: Upload coverage
uses: codecov/codecov-action@v1
if: success()
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/clover.xml

25
.github/workflows/validate.yml vendored Normal file
View File

@ -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

59
Dockerfile.dev Normal file
View File

@ -0,0 +1,59 @@
#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 deps AS test
COPY --from=docker /usr/local/bin/docker /usr/bin/
ARG TARGETOS
ARG TARGETARCH
ENV RUNNER_TEMP=/tmp/github_runner
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
ARG BUILDX_VERSION=v0.5.1
RUN mkdir -p /usr/local/lib/docker/cli-plugins \
&& curl -fsSL https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.$TARGETOS-$TARGETARCH > /usr/local/lib/docker/cli-plugins/docker-buildx \
&& chmod +x /usr/local/lib/docker/cli-plugins/docker-buildx \
&& docker buildx version
COPY . .
RUN --mount=type=cache,target=/src/node_modules \
yarn run test
FROM scratch AS test-coverage
COPY --from=test /src/coverage /coverage/
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"]

930
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

54
docker-bake.hcl Normal file
View File

@ -0,0 +1,54 @@
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-coverage"
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"
}