Skip to content

Commit

Permalink
Fix docker mount path
Browse files Browse the repository at this point in the history
  • Loading branch information
tyhal committed Jun 29, 2021
1 parent 9c8cd0e commit d1f3587
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 32 deletions.
1 change: 0 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ jobs:
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/crie:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FROM tyhal/hadolint:0.0.2 as hadolint_layer
FROM hashicorp/terraform:1.0.1 as terraform_layer

FROM golang:1.16.5-alpine3.12 as go_layer
FROM golang:1.16.5-alpine3.13 as go_layer
RUN apk --no-cache add git wget
ENV CGO_ENABLED=0

Expand All @@ -22,15 +22,15 @@ COPY internal /crie/internal
COPY pkg /crie/pkg
RUN --mount=type=cache,target=/root/.cache/go-build go build ./cmd/crie

FROM alpine:3.12.1 as clang_layer
FROM alpine:3.13.0 as clang_layer
RUN apk --no-cache add clang

# ~~~ ~~~ ~~~~~~~~~~~~~~~~~ ~~~ ~~~
# ~~~~~~~~~~~~~~~~~ ~~~ TOP LAYER ~~~ ~~~~~~~~~~~~~~~~~
# ~~~ ~~~ ~~~~~~~~~~~~~~~~~ ~~~ ~~~

# Alpine :ok_hand:
FROM alpine:3.12.1
FROM alpine:3.13.0
RUN apk --no-cache add git wget ca-certificates \
&& update-ca-certificates

Expand All @@ -40,9 +40,9 @@ RUN adduser -D standards
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# [ NPM pkgs]
RUN apk add --no-cache nodejs-npm && npm install -g jsonlint2 remark-cli remark-preset-lint-recommended standard
RUN apk add --no-cache npm && npm install -g jsonlint2 remark-cli remark-preset-lint-recommended standard

# [ OS pkgs]
# [ OS pkgs] - We pull clang-format out specifically because we don't need the rest of clang
RUN apk --no-cache add gmp libxml2
COPY --from=clang_layer /usr/lib/libclang-cpp.so.10 /usr/lib/libclang-cpp.so.10
COPY --from=clang_layer /usr/lib/libLLVM-10.so /usr/lib/libLLVM-10.so
Expand Down
2 changes: 1 addition & 1 deletion cmd/crie/conf/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var LanguageList = []linter.Language{
Docker: cli.DockerCmd{Image: hadolintImg}}},
{
Name: `sh`,
Match: regexp.MustCompile(`\.sh$|script/[^.]*$`),
Match: regexp.MustCompile(`\.sh$|/script/[^.]*$|^script/[^.]*$`),
Fmt: &shfmt.Lint{Language: syntax.LangPOSIX},
Chk: &cli.Lint{Bin: `shellcheck`, FrontPar: cli.Par{`-x`, `--shell=sh`, `-Calways`},
Docker: cli.DockerCmd{Image: hadolintImg}}},
Expand Down
2 changes: 1 addition & 1 deletion cmd/crie/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var majorNum = "0"
var minorOffset = 0
var patchNum = "64"
var patchNum = "80"

//`
// |> crie: the act of crying and dying at the same time
Expand Down
49 changes: 37 additions & 12 deletions pkg/linter/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (e *Lint) WillRun() error {
if err := e.startDocker(); err != nil {
return err
}

log.Warn("it's more efficient to have " + e.Bin + " installed locally")
}
return nil
Expand All @@ -61,6 +62,7 @@ func (e *Lint) WillRun() error {
func (e *Lint) execDocker(params []string, stdout io.Writer) error {
ctx := context.Background()
cmd := append([]string{"/bin/" + e.Bin}, params...)
log.Trace(cmd)
config := types.ExecConfig{
Cmd: cmd,
Env: os.Environ(),
Expand Down Expand Up @@ -102,32 +104,54 @@ func (e *Lint) execDocker(params []string, stdout io.Writer) error {
}
}

func (e *Lint) startDocker() error {
ctx := context.Background()
c, err := client.NewEnvClient()
if err != nil {
return err
}
func (e *Lint) pullDocker(ctx context.Context) error {

// Ensure we have the image downloaded
pullstat, err := c.ImagePull(ctx, e.Docker.Image, types.ImagePullOptions{})
pullstat, err := e.Docker.client.ImagePull(ctx, e.Docker.Image, types.ImagePullOptions{})
if err != nil {
log.WithFields(log.Fields{
"stage": "docker pull",
"image": e.Docker.Image,
}).Fatal(err)
return err
}

var pullOut bytes.Buffer
if _, err = io.Copy(&pullOut, pullstat); err != nil {
panic(err)
}
_, err = io.Copy(&pullOut, pullstat)
log.Debug(pullOut.String())

e.Docker.client = c
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
return err
}

func (e *Lint) startDocker() error {
ctx := context.Background()

// Add our client
{
c, err := client.NewEnvClient()
if err != nil {
return err
}
e.Docker.client = c
}

_, err := e.Docker.client.ImageHistory(ctx, e.Docker.Image)
if err != nil {
if err := e.pullDocker(ctx); err != nil {
return err
}
}

// Ensure we can mount our filesystem to the same path inside the container
wd, err := os.Getwd()
if err != nil {
return err
}
dir, err := filepath.Abs(wd)
if err != nil {
return err
}

resp, err := e.Docker.client.ContainerCreate(ctx,
&container.Config{
Entrypoint: []string{"/bin/sleep"},
Expand All @@ -148,6 +172,7 @@ func (e *Lint) startDocker() error {
if err != nil {
return err
}

if err := e.Docker.client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
return err
}
Expand Down
11 changes: 0 additions & 11 deletions pkg/linter/shfmt/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"bytes"
maybeio "github.com/google/renameio/maybe"
"io"
"mvdan.cc/sh/v3/fileutil"
"mvdan.cc/sh/v3/syntax"
"os"
)
Expand All @@ -25,16 +24,6 @@ func (s *shfmt) formatPath(path string, checkShebang bool) error {
}
defer f.Close()
readBuf.Reset()
if checkShebang {
n, err := f.Read(copyBuf[:32])
if err != nil {
return err
}
if !fileutil.HasShebang(copyBuf[:n]) {
return nil
}
readBuf.Write(copyBuf[:n])
}
if _, err := io.CopyBuffer(&readBuf, f, copyBuf); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion verify/lang/cpp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM gcc:11.1.0
RUN apt-get update -y \
&& apt-get install -y \
--no-install-recommends \
cmake=3.13.4* \
cmake=3.18.4* \
&& rm -rf /var/lib/apt/lists/*
COPY . /src/
WORKDIR /build/
Expand Down

0 comments on commit d1f3587

Please sign in to comment.