Skip to content

Commit b3b0ca3

Browse files
authored
Merge pull request #202 from crazy-max/bake-dev
Container based developer flow
2 parents c58c687 + 0307a52 commit b3b0ca3

File tree

8 files changed

+345
-3254
lines changed

8 files changed

+345
-3254
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.github/CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ Contributions to this project are [released](https://help.github.com/articles/gi
1515
7. Push to your fork and [submit a pull request](https://github.com/docker/build-push-action/compare)
1616
8. Pat your self on the back and wait for your pull request to be reviewed and merged.
1717

18+
## Container based developer flow
19+
20+
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.
21+
22+
```
23+
# format code and build javascript artifacts
24+
docker buildx bake pre-checkin
25+
26+
# validate all code has correctly formatted and built
27+
docker buildx bake validate
28+
29+
# run tests
30+
docker buildx bake test
31+
```
32+
1833
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
1934

2035
- Make sure the `README.md` and any other relevant **documentation are kept up-to-date**.

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ on:
99
- master
1010

1111
jobs:
12+
test-containerized:
13+
runs-on: ubuntu-latest
14+
steps:
15+
-
16+
name: Checkout
17+
uses: actions/checkout@v2.3.3
18+
-
19+
name: Validate
20+
run: docker buildx bake validate
21+
-
22+
name: Test
23+
run: docker buildx bake test
24+
1225
test:
1326
runs-on: ubuntu-latest
1427
steps:

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#syntax=docker/dockerfile:1.1-experimental
2+
3+
FROM node:12 AS deps
4+
WORKDIR /src
5+
COPY package.json yarn.lock ./
6+
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \
7+
yarn install
8+
9+
FROM scratch AS update-yarn
10+
COPY --from=deps /src/yarn.lock /
11+
12+
FROM deps AS validate-yarn
13+
COPY .git .git
14+
RUN status=$(git status --porcelain -- yarn.lock); if [ -n "$status" ]; then echo $status; exit 1; fi
15+
16+
FROM deps AS base
17+
COPY . .
18+
19+
FROM base AS build
20+
RUN yarn build
21+
22+
FROM deps AS test
23+
COPY --from=docker /usr/local/bin/docker /usr/bin/
24+
ARG TARGETOS
25+
ARG TARGETARCH
26+
ARG BUILDX_VERSION=v0.4.2
27+
ENV RUNNER_TEMP=/tmp/github_runner
28+
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
29+
RUN mkdir -p /usr/local/lib/docker/cli-plugins && \
30+
curl -fsSL https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.$TARGETOS-$TARGETARCH > /usr/local/lib/docker/cli-plugins/docker-buildx && \
31+
chmod +x /usr/local/lib/docker/cli-plugins/docker-buildx && \
32+
docker buildx version
33+
COPY . .
34+
RUN yarn run test
35+
36+
FROM base AS run-format
37+
RUN yarn run format
38+
39+
FROM scratch AS format
40+
COPY --from=run-format /src/src/*.ts /src/
41+
42+
FROM base AS validate-format
43+
RUN yarn run format-check
44+
45+
FROM scratch AS dist
46+
COPY --from=build /src/dist/ /dist/
47+
48+
FROM build AS validate-build
49+
RUN status=$(git status --porcelain -- dist); if [ -n "$status" ]; then echo $status; exit 1; fi
50+
51+
FROM base AS dev
52+
ENTRYPOINT ["bash"]

__tests__/buildx.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import * as semver from 'semver';
44
import * as buildx from '../src/buildx';
5+
import * as docker from '../src/docker';
56
import * as exec from '@actions/exec';
67
import * as context from '../src/context';
78

@@ -91,11 +92,18 @@ describe('isLocalOrTarExporter', () => {
9192
});
9293

9394
describe('getVersion', () => {
94-
it('valid', async () => {
95-
const version = await buildx.getVersion();
96-
console.log(`version: ${version}`);
97-
expect(semver.valid(version)).not.toBeNull();
98-
}, 100000);
95+
async function isDaemonRunning() {
96+
return await docker.isDaemonRunning();
97+
}
98+
(isDaemonRunning() ? it : it.skip)(
99+
'valid',
100+
async () => {
101+
const version = await buildx.getVersion();
102+
console.log(`version: ${version}`);
103+
expect(semver.valid(version)).not.toBeNull();
104+
},
105+
100000
106+
);
99107
});
100108

101109
describe('parseVersion', () => {

0 commit comments

Comments
 (0)