Skip to content

Commit

Permalink
feat: Container based developer flow
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Nov 22, 2020
1 parent d19982d commit 796c764
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -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:
Expand Down
46 changes: 46 additions & 0 deletions 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"]
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -24,6 +24,7 @@ ___
* [inputs](#inputs)
* [environment variables](#environment-variables)
* [Limitation](#limitation)
* [Development](#development)
* [License](#license)

## Usage
Expand Down Expand Up @@ -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 changes: 53 additions & 0 deletions 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"
}

0 comments on commit 796c764

Please sign in to comment.