feat: Container based developer flow (#258)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-11-22 23:34:12 +01:00 committed by GitHub
parent d19982d4d2
commit a61bc075fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 30 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
node_modules

View File

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

View File

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

46
Dockerfile.dev Normal file
View File

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

View File

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

53
docker-bake.hcl Normal file
View File

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