Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container based developer flow #258

Merged
merged 1 commit into from Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
node_modules
30 changes: 0 additions & 30 deletions .github/workflows/pre-checkin.yml

This file was deleted.

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