Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 801e43c

Browse files
authored
Merge pull request #16 from crazy-max/parser-gomod
go module for dockerfile/parser
2 parents 6b4be8a + 73f1346 commit 801e43c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+5905
-34
lines changed

Diff for: .github/workflows/build.yml

+4-12
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,20 @@ jobs:
108108
- test
109109
runs-on: ubuntu-latest
110110
steps:
111+
-
112+
name: Checkout
113+
uses: actions/checkout@v2
111114
-
112115
name: Download coverage files
113116
uses: actions/download-artifact@v2
114117
with:
115118
name: coverage
116119
path: ./coverage
117-
-
118-
name: List coverage files
119-
uses: actions/github-script@v3
120-
id: files
121-
with:
122-
result-encoding: string
123-
script: |
124-
return require('fs').readdirSync('./coverage', {withFileTypes: true})
125-
.filter(item => !item.isDirectory())
126-
.map(item => `./coverage/${item.name}`)
127-
.join(',');
128120
-
129121
name: Send to Codecov
130122
uses: codecov/codecov-action@v2
131123
with:
132-
files: ${{ steps.files.outputs.result }}
124+
directory: ./coverage
133125

134126
build:
135127
needs:

Diff for: .github/workflows/parser.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: parser
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'master'
8+
- 'v[0-9]*'
9+
tags:
10+
- 'parser/v*'
11+
pull_request:
12+
branches:
13+
- 'master'
14+
- 'v[0-9]*'
15+
16+
env:
17+
WORKDIR: ./parser
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
steps:
23+
-
24+
name: Checkout
25+
uses: actions/checkout@v2
26+
-
27+
name: Test
28+
uses: docker/bake-action@v1
29+
with:
30+
files: ${{ env.WORKDIR }}/docker-bake.hcl
31+
targets: test
32+
set: |
33+
*.context=${{ env.WORKDIR }}
34+
*.output=${{ env.WORKDIR }}/coverage
35+
-
36+
name: Send to Codecov
37+
uses: codecov/codecov-action@v2
38+
with:
39+
directory: ${{ env.WORKDIR }}/coverage

Diff for: Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ vendor:
2323
mod-outdated:
2424
$(BUILDX_CMD) bake mod-outdated
2525

26-
validate: lint test validate-vendor
26+
validate: lint test test-parser validate-vendor
2727

2828
lint:
2929
$(BUILDX_CMD) bake lint
@@ -34,4 +34,11 @@ test:
3434
validate-vendor:
3535
$(BUILDX_CMD) bake validate-vendor
3636

37-
.PHONY: image vendor mod-outdated validate lint test validate-vendor
37+
test-parser:
38+
$(BUILDX_CMD) bake \
39+
--file ./parser/docker-bake.hcl \
40+
--set *.context=./parser \
41+
--set *.output=./parser/coverage \
42+
test
43+
44+
.PHONY: image vendor mod-outdated validate lint test validate-vendor test-parser

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# BuildKit Dockerfile frontend
22

33
<!-- FIXME: Remove comment when moved to docker org
4+
[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/dockerfile)
45
[![GitHub release](https://img.shields.io/github/release/docker/dockerfile.svg?style=flat-square)](https://github.com/docker/dockerfile/releases/latest)
5-
[![Build Status](https://github.com/docker/dockerfile/workflows/build/badge.svg)](https://github.com/docker/dockerfile/actions?query=workflow%3Abuild)
6+
[![Build Status](https://img.shields.io/github/workflow/status/docker/dockerfile/build?label=build&logo=github&style=flat-square)](https://github.com/docker/dockerfile/actions?query=workflow%3Abuild)
67
[![Docker Stars](https://img.shields.io/docker/stars/docker/dockerfile.svg?style=flat-square&logo=docker)](https://hub.docker.com/r/docker/dockerfile/)
78
[![Docker Pulls](https://img.shields.io/docker/pulls/docker/dockerfile.svg?style=flat-square&logo=docker)](https://hub.docker.com/r/docker/dockerfile/)
89

Diff for: builder/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"github.com/containerd/containerd/platforms"
1717
"github.com/docker/distribution/reference"
1818
"github.com/docker/dockerfile/dockerfile2llb"
19-
"github.com/docker/dockerfile/dockerignore"
2019
"github.com/docker/dockerfile/parser"
20+
"github.com/docker/dockerfile/parser/dockerignore"
2121
"github.com/docker/go-units"
2222
controlapi "github.com/moby/buildkit/api/services/control"
2323
"github.com/moby/buildkit/client/llb"

Diff for: codecov.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
comment: false
2+
github_checks:
3+
annotations: false
4+
5+
fixes:
6+
- "vendor/github.com/docker/dockerfile::" # move path to its original location

Diff for: dockerfile2llb/convert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616

1717
"github.com/containerd/containerd/platforms"
1818
"github.com/docker/distribution/reference"
19-
"github.com/docker/dockerfile/instructions"
2019
"github.com/docker/dockerfile/parser"
21-
"github.com/docker/dockerfile/shell"
20+
"github.com/docker/dockerfile/parser/instructions"
21+
"github.com/docker/dockerfile/parser/shell"
2222
"github.com/docker/go-connections/nat"
2323
"github.com/moby/buildkit/client/llb"
2424
"github.com/moby/buildkit/client/llb/imagemetaresolver"

Diff for: dockerfile2llb/convert_norunsecurity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package dockerfile2llb
55

66
import (
7-
"github.com/docker/dockerfile/instructions"
7+
"github.com/docker/dockerfile/parser/instructions"
88
"github.com/moby/buildkit/client/llb"
99
)
1010

Diff for: dockerfile2llb/convert_runmount.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strconv"
1010
"strings"
1111

12-
"github.com/docker/dockerfile/instructions"
12+
"github.com/docker/dockerfile/parser/instructions"
1313
"github.com/moby/buildkit/client/llb"
1414
"github.com/moby/buildkit/solver/pb"
1515
"github.com/pkg/errors"

Diff for: dockerfile2llb/convert_runnetwork.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dockerfile2llb
33
import (
44
"github.com/pkg/errors"
55

6-
"github.com/docker/dockerfile/instructions"
6+
"github.com/docker/dockerfile/parser/instructions"
77
"github.com/moby/buildkit/client/llb"
88
"github.com/moby/buildkit/solver/pb"
99
)

Diff for: dockerfile2llb/convert_runsecurity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package dockerfile2llb
66
import (
77
"github.com/pkg/errors"
88

9-
"github.com/docker/dockerfile/instructions"
9+
"github.com/docker/dockerfile/parser/instructions"
1010
"github.com/moby/buildkit/client/llb"
1111
"github.com/moby/buildkit/solver/pb"
1212
)

Diff for: dockerfile2llb/convert_secrets.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dockerfile2llb
33
import (
44
"path"
55

6-
"github.com/docker/dockerfile/instructions"
6+
"github.com/docker/dockerfile/parser/instructions"
77
"github.com/moby/buildkit/client/llb"
88
"github.com/pkg/errors"
99
)

Diff for: dockerfile2llb/convert_ssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dockerfile2llb
22

33
import (
4-
"github.com/docker/dockerfile/instructions"
4+
"github.com/docker/dockerfile/parser/instructions"
55
"github.com/moby/buildkit/client/llb"
66
"github.com/pkg/errors"
77
)

Diff for: dockerfile2llb/convert_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/docker/dockerfile/instructions"
9-
"github.com/docker/dockerfile/shell"
8+
"github.com/docker/dockerfile/parser/instructions"
9+
"github.com/docker/dockerfile/parser/shell"
1010
"github.com/moby/buildkit/exporter/containerimage/exptypes"
1111
"github.com/moby/buildkit/util/appcontext"
1212
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"

Diff for: dockerfile2llb/platform.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dockerfile2llb
22

33
import (
44
"github.com/containerd/containerd/platforms"
5-
"github.com/docker/dockerfile/instructions"
5+
"github.com/docker/dockerfile/parser/instructions"
66
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
77
)
88

Diff for: go.mod

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ require (
66
github.com/containerd/containerd v1.6.0-beta.3
77
github.com/containerd/continuity v0.2.1
88
github.com/docker/distribution v2.7.1+incompatible
9-
github.com/docker/docker v20.10.12+incompatible // master
9+
github.com/docker/docker v20.10.12+incompatible // master (v21.xx-dev)
10+
github.com/docker/dockerfile/parser v0.0.0-00010101000000-000000000000
1011
github.com/docker/go-connections v0.4.0
1112
github.com/docker/go-units v0.4.0
12-
github.com/google/go-cmp v0.5.6
1313
github.com/moby/buildkit v0.9.3
1414
github.com/moby/sys/signal v0.6.0
1515
github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283
@@ -37,6 +37,7 @@ require (
3737
github.com/gogo/protobuf v1.3.2 // indirect
3838
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3939
github.com/golang/protobuf v1.5.2 // indirect
40+
github.com/google/go-cmp v0.5.6 // indirect
4041
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
4142
github.com/google/uuid v1.3.0 // indirect
4243
github.com/gorilla/mux v1.8.0 // indirect
@@ -75,6 +76,7 @@ require (
7576

7677
replace (
7778
github.com/docker/docker => github.com/docker/docker v20.10.3-0.20211208011758-87521affb077+incompatible
79+
github.com/docker/dockerfile/parser => ./parser
7880
github.com/moby/buildkit => github.com/moby/buildkit v0.9.1-0.20220107201744-ffe2301031c8
7981
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/httptrace/otelhttptrace v0.0.0-20211026174723-2f82a1e0c997
8082
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/otelhttp v0.0.0-20211026174723-2f82a1e0c997

Diff for: parser/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

Diff for: parser/Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# syntax=docker/dockerfile:1-labs
2+
3+
ARG GO_VERSION=1.17
4+
5+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
6+
RUN apk add --no-cache file git
7+
ENV CGO_ENABLED=0
8+
ENV GOFLAGS=-mod=mod
9+
WORKDIR /src
10+
11+
FROM base AS test
12+
RUN --mount=type=bind,target=. \
13+
--mount=type=cache,target=/root/.cache \
14+
--mount=type=cache,target=/go/pkg/mod \
15+
go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./... && \
16+
go tool cover -func=/tmp/coverage.txt
17+
18+
FROM scratch AS test-coverage
19+
COPY --from=test /tmp/coverage.txt /coverage.txt

Diff for: parser/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!-- FIXME: Uncomment when moved to docker org
2+
[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/dockerfile/parser)
3+
[![Test Status](https://img.shields.io/github/workflow/status/docker/dockerfile/parser?label=test&logo=github&style=flat-square)](https://github.com/docker/dockerfile/actions?query=workflow%3Aparser)
4+
-->
5+
6+
## About
7+
8+
This directory contains the parser and tree dumper for Dockerfiles.
9+
10+
## Test
11+
12+
```shell
13+
$ docker buildx bake test
14+
```
15+
16+
## Usage
17+
18+
```shell
19+
go get github.com/docker/dockerfile/parser
20+
```
21+
22+
```go
23+
package main
24+
25+
import (
26+
"bytes"
27+
"os"
28+
29+
"github.com/docker/dockerfile/parser"
30+
)
31+
32+
func main() {
33+
b, err := os.ReadFile("Dockerfile")
34+
if err != nil {
35+
panic(err)
36+
}
37+
38+
_, err = parser.Parse(bytes.NewReader(b))
39+
if err != nil {
40+
panic(err)
41+
}
42+
}
43+
```
File renamed without changes.

Diff for: parser/docker-bake.hcl

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "GO_VERSION" {
2+
default = "1.17"
3+
}
4+
5+
target "_common" {
6+
args = {
7+
GO_VERSION = GO_VERSION
8+
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
9+
}
10+
}
11+
12+
target "test" {
13+
inherits = ["_common"]
14+
target = "test-coverage"
15+
output = ["./coverage"]
16+
}
File renamed without changes.
File renamed without changes.

Diff for: parser/go.mod

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module github.com/docker/dockerfile/parser
2+
3+
go 1.17
4+
5+
require (
6+
github.com/docker/docker v20.10.12+incompatible // master
7+
github.com/google/go-cmp v0.5.6
8+
github.com/moby/buildkit v0.9.3
9+
github.com/pkg/errors v0.9.1
10+
github.com/stretchr/testify v1.7.0
11+
)
12+
13+
require (
14+
github.com/agext/levenshtein v1.2.3 // indirect
15+
github.com/containerd/typeurl v1.0.2 // indirect
16+
github.com/davecgh/go-spew v1.1.1 // indirect
17+
github.com/docker/go-connections v0.4.0 // indirect
18+
github.com/docker/go-units v0.4.0 // indirect
19+
github.com/gogo/protobuf v1.3.2 // indirect
20+
github.com/golang/protobuf v1.5.2 // indirect
21+
github.com/opencontainers/go-digest v1.0.0 // indirect
22+
github.com/opencontainers/image-spec v1.0.1 // indirect
23+
github.com/pmezard/go-difflib v1.0.0 // indirect
24+
google.golang.org/protobuf v1.27.1 // indirect
25+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
26+
)
27+
28+
replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20211208011758-87521affb077+incompatible

0 commit comments

Comments
 (0)