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

[pull] master from jessfraz:master #4

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .github/workflows/make-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
on: push
name: make all
jobs:
makeall:
name: make all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: make all
uses: docker://golang:latest
with:
entrypoint: bash
args: -c "go get honnef.co/go/tools/cmd/staticcheck && go get golang.org/x/lint/golint && git checkout . && make all"
11 changes: 11 additions & 0 deletions .github/workflows/make-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: push
name: make image
jobs:
makeimage:
name: make image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: make image
run: make image
shell: bash
29 changes: 29 additions & 0 deletions .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
tags:
- v*
name: make release
jobs:
makerelease:
name: make release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: make release
uses: docker://golang:latest
with:
args: make release
- name: upload assets
uses: docker://r.j3ss.co/github-dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
entrypoint: bash
args: -c "upload-assets ./cross/*"
- name: update release body
uses: docker://r.j3ss.co/pepper
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
entrypoint: sh
args: -c "pepper release --repo $GITHUB_REPOSITORY -d --nouser"
15 changes: 15 additions & 0 deletions .github/workflows/toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
push:
branches:
- master # Push events on master branch
name: Table of Contents Generator
jobs:
generateTOC:
name: TOC Generator
runs-on: ubuntu-latest
steps:
- name: TOC Generator
uses: technote-space/toc-generator@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_PATHS: "README.md"
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion .traviskey

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018 Jessica Frazelle
Copyright (c) 2020 Jessica Frazelle

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
55 changes: 40 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# dockfmt

[![Travis CI](https://img.shields.io/travis/jessfraz/dockfmt.svg?style=for-the-badge)](https://travis-ci.org/jessfraz/dockfmt)
[![make-all](https://github.com/jessfraz/dockfmt/workflows/make%20all/badge.svg)](https://github.com/jessfraz/dockfmt/actions?query=workflow%3A%22make+all%22)
[![make-image](https://github.com/jessfraz/dockfmt/workflows/make%20image/badge.svg)](https://github.com/jessfraz/dockfmt/actions?query=workflow%3A%22make+image%22)
[![GoDoc](https://img.shields.io/badge/godoc-reference-5272B4.svg?style=for-the-badge)](https://godoc.org/github.com/jessfraz/dockfmt)

Dockerfile format.

**NOTE:** This is a work in progress so calm yourself if you want to file 80 bajillion
issues.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

<!-- toc -->

- [Installation](#installation)
+ [Binaries](#binaries)
+ [Via Go](#via-go)
- [Binaries](#binaries)
- [Via Go](#via-go)
- [Usage](#usage)
* [Format](#format)
+ [Get help](#get-help)
+ [Get a diff](#get-a-diff)
+ [List multiple files with different output](#list-multiple-files-with-different-output)
* [Base image inspection](#base-image-inspection)
* [Maintainer inspection](#maintainer-inspection)
- [Format](#format)
- [Get help](#get-help)
- [Get a diff](#get-a-diff)
- [List multiple files with different output](#list-multiple-files-with-different-output)
- [Base image inspection](#base-image-inspection)
- [Maintainer inspection](#maintainer-inspection)
- [Stage inspection](#stage-inspection)
- [Workdir inspection](#workdir-inspection)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

<!-- tocstop -->

## Installation

Expand Down Expand Up @@ -55,6 +59,8 @@ Commands:
dump Dump parsed Dockerfile(s).
fmt Format the Dockerfile(s).
maintainer List the maintainer for the Dockerfile(s).
stages List the stages in the Dockerfile.
workdir List the workdirs for the Dockerfile(s).
version Show the version information.
```

Expand All @@ -64,7 +70,7 @@ Commands:

```console
$ dockfmt fmt -h
Usage: dockfmt fmt [OPTIONS] DOCKERFILE [DOCKERFILE...]
Usage: dockfmt fmt [OPTIONS] [DOCKERFILE...]

Format the Dockerfile(s).

Expand All @@ -79,7 +85,7 @@ Flags:
#### Get a diff

```console
$ dockfmt format -d htop/Dockerfile
$ dockfmt fmt -d htop/Dockerfile
diff htop/Dockerfile dockfmt/htop/Dockerfile
--- /tmp/dockfmt143910590 2016-09-19 15:59:22.612250710 -0700
+++ /tmp/dockfmt412224773 2016-09-19 15:59:22.612250710 -0700
Expand Down Expand Up @@ -153,4 +159,23 @@ Christian Koep <[email protected]> 11
Justin Garrison <[email protected]> 2
Daniel Romero <[email protected]> 1
Cris G [email protected] 1
```
```

### Stage inspection

```console
$ dockfmt stages Dockerfile
STAGE INTERPOLATED
health-check false
python-deps false
stage-2 true
```

### Workdir inspection

```console
$ dockfmt workdir */Dockerfile */*/Dockerfile
WORKDIR COUNT
/srv 3
/app 1
```
4 changes: 2 additions & 2 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const baseHelp = `List the base image used in the Dockerfile(s).`

func (cmd *baseCommand) Name() string { return "base" }
func (cmd *baseCommand) Args() string { return "[OPTIONS] DOCKERFILE [DOCKERFILE...]" }
func (cmd *baseCommand) Args() string { return "[OPTIONS] [DOCKERFILE...]" }
func (cmd *baseCommand) ShortHelp() string { return baseHelp }
func (cmd *baseCommand) LongHelp() string { return baseHelp }
func (cmd *baseCommand) Hidden() bool { return false }
Expand All @@ -25,7 +25,7 @@ type baseCommand struct{}
func (cmd *baseCommand) Run(ctx context.Context, args []string) error {
images := map[string]int{}

err := forFile(args, func(f string, nodes []*parser.Node) error {
err := forFile(args, func(f *os.File, nodes []*parser.Node) error {
for _, n := range nodes {
images = nodeSearch("from", n, images)
}
Expand Down
4 changes: 2 additions & 2 deletions basic.mk
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ release: *.go VERSION.txt prebuild ## Builds the cross-compiled binaries, naming
.PHONY: bump-version
BUMP := patch
bump-version: ## Bump the version in the version file. Set BUMP to [ patch | major | minor ].
@$(GO) get -u github.com/jessfraz/junk/sembump # update sembump tool
@$(GO) get -u github.com/jessfraz/junk/sembump || true # update sembump tool
$(eval NEW_VERSION = $(shell sembump --kind $(BUMP) $(VERSION)))
@echo "Bumping VERSION.txt from $(VERSION) to $(NEW_VERSION)"
echo $(NEW_VERSION) > VERSION.txt
Expand All @@ -150,7 +150,7 @@ bump-version: ## Bump the version in the version file. Set BUMP to [ patch | maj
.PHONY: tag
tag: ## Create a new git tag to prepare to build a release.
git tag -sa $(VERSION) -m "$(VERSION)"
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a travis build."
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a release."

REGISTRY := r.j3ss.co
.PHONY: image
Expand Down
7 changes: 4 additions & 3 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"flag"
"fmt"
"os"

"github.com/moby/buildkit/frontend/dockerfile/parser"
)

const dumpHelp = `Dump parsed Dockerfile(s).`

func (cmd *dumpCommand) Name() string { return "dump" }
func (cmd *dumpCommand) Args() string { return "[OPTIONS] DOCKERFILE [DOCKERFILE...]" }
func (cmd *dumpCommand) Args() string { return "[OPTIONS] [DOCKERFILE...]" }
func (cmd *dumpCommand) ShortHelp() string { return dumpHelp }
func (cmd *dumpCommand) LongHelp() string { return dumpHelp }
func (cmd *dumpCommand) Hidden() bool { return false }
Expand All @@ -21,8 +22,8 @@ func (cmd *dumpCommand) Register(fs *flag.FlagSet) {}
type dumpCommand struct{}

func (cmd *dumpCommand) Run(ctx context.Context, args []string) error {
return forFile(args, func(f string, nodes []*parser.Node) error {
fmt.Println(f)
return forFile(args, func(f *os.File, nodes []*parser.Node) error {
fmt.Println(f.Name())
if len(nodes) > 0 {
fmt.Println(nodes[0].Dump())
}
Expand Down
18 changes: 9 additions & 9 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
const formatHelp = `Format the Dockerfile(s).`

func (cmd *formatCommand) Name() string { return "fmt" }
func (cmd *formatCommand) Args() string { return "[OPTIONS] DOCKERFILE [DOCKERFILE...]" }
func (cmd *formatCommand) Args() string { return "[OPTIONS] [DOCKERFILE...]" }
func (cmd *formatCommand) ShortHelp() string { return formatHelp }
func (cmd *formatCommand) LongHelp() string { return formatHelp }
func (cmd *formatCommand) Hidden() bool { return false }
Expand Down Expand Up @@ -51,15 +51,15 @@ type file struct {
}

func (cmd *formatCommand) Run(ctx context.Context, args []string) error {
err := forFile(args, func(f string, nodes []*parser.Node) error {
og, err := ioutil.ReadFile(f)
err := forFile(args, func(f *os.File, nodes []*parser.Node) error {
og, err := ioutil.ReadAll(f)
if err != nil {
return err
}

df := file{
currentLine: 1,
name: f,
name: f.Name(),
originalFile: og,
}

Expand All @@ -78,26 +78,26 @@ func (cmd *formatCommand) Run(ctx context.Context, args []string) error {
if err != nil {
return fmt.Errorf("computing diff: %s", err)
}
fmt.Printf("diff %s dockfmt/%s\n", f, f)
fmt.Printf("diff %s dockfmt/%s\n", f.Name(), f.Name())
os.Stdout.Write(d)
}

if cmd.list {
if !bytes.Equal(og, []byte(result)) {
fmt.Fprintln(os.Stdout, f)
fmt.Fprintln(os.Stdout, f.Name())
}
}

// write to the file
if cmd.write {
// make a temporary backup before overwriting original
bakname, err := backupFile(f+".", og, 0644)
bakname, err := backupFile(f.Name()+".", og, 0644)
if err != nil {
return err
}

if err := ioutil.WriteFile(f, []byte(result), 0644); err != nil {
os.Rename(bakname, f)
if err := ioutil.WriteFile(f.Name(), []byte(result), 0644); err != nil {
os.Rename(bakname, f.Name())
return err
}

Expand Down
28 changes: 15 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module github.com/jessfraz/dockfmt

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/genuinetools/pkg v0.0.0-20180717194616-e057fa50f234
github.com/google/go-cmp v0.2.0 // indirect
github.com/moby/buildkit v0.0.0-20180717184648-628681f8e4aa
github.com/onsi/gomega v1.4.2 // indirect
github.com/pkg/errors v0.8.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.0.5
github.com/stretchr/testify v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8 // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gotest.tools v2.1.0+incompatible // indirect
github.com/genuinetools/pkg v0.0.0-20181022210355-2fcf164d37cb
github.com/moby/buildkit v0.6.1
github.com/sirupsen/logrus v1.4.3-0.20190807103436-de736cf91b92
)

replace github.com/hashicorp/go-immutable-radix => github.com/tonistiigi/go-immutable-radix v0.0.0-20170803185627-826af9ccf0fe

replace github.com/jaguilar/vt100 => github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305

replace github.com/containerd/containerd v1.3.0-0.20190507210959-7c1e88399ec0 => github.com/containerd/containerd v1.3.0-rc.1.0.20190916145203-86442dfbb9c7

replace github.com/docker/docker v1.14.0-0.20190319215453-e7b5f7dbe98c => github.com/docker/docker v1.4.2-0.20190916154449-92cc603036dd

replace golang.org/x/crypto v0.0.0-20190129210102-0709b304e793 => golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7

go 1.13
Loading