Skip to content

Commit c8e09bf

Browse files
Merge remote-tracking branch 'upstream/master' into fix-parse-secret-containing-equal-character
# Conflicts: # __tests__/buildx.test.ts
2 parents 8616d52 + b3b0ca3 commit c8e09bf

File tree

7 files changed

+143
-5
lines changed

7 files changed

+143
-5
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 context from '../src/context';
67

78
const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
@@ -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', () => {

docker-bake.hcl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
group "default" {
2+
targets = ["build"]
3+
}
4+
5+
group "pre-checkin" {
6+
targets = ["update-yarn", "format", "build"]
7+
}
8+
9+
group "validate" {
10+
targets = ["validate-format", "validate-build", "validate-yarn"]
11+
}
12+
13+
target "update-yarn" {
14+
target = "update-yarn"
15+
output = ["."]
16+
}
17+
18+
target "build" {
19+
target = "dist"
20+
output = ["."]
21+
}
22+
23+
target "test" {
24+
target = "test"
25+
}
26+
27+
target "format" {
28+
target = "format"
29+
output = ["."]
30+
}
31+
32+
target "validate-format" {
33+
target = "validate-format"
34+
}
35+
36+
target "validate-build" {
37+
target = "validate-build"
38+
}
39+
40+
target "validate-yarn" {
41+
target = "validate-yarn"
42+
}

src/docker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as exec from './exec';
2+
3+
export async function isDaemonRunning(): Promise<boolean> {
4+
return await exec.exec(`docker`, ['version', '--format', '{{.Server.Os}}'], true).then(res => {
5+
return !res.stdout.includes(' ') && res.success;
6+
});
7+
}

0 commit comments

Comments
 (0)