diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index cc33f56..49fbf5e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -98,3 +98,23 @@ jobs: GOOS: windows GOARCH: amd64 run: make build + + docker: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Build 'dev' Docker image + if: "!contains(github.ref, 'refs/heads/master')" + run: DOCKER_TAG=${{ github.sha }} make docker + + - name: Build and push 'edge' Docker image + if: "contains(github.ref, 'refs/heads/master')" + run: | + echo ${REGISTRY_PASSWORD} | docker login -u ${REGISTRY_USERNAME} --password-stdin quay.io + DOCKER_TAG=edge make docker push + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} diff --git a/.github/workflows/prerelease.yaml b/.github/workflows/prerelease.yaml index 8c927cf..15c56cc 100644 --- a/.github/workflows/prerelease.yaml +++ b/.github/workflows/prerelease.yaml @@ -33,3 +33,23 @@ jobs: prerelease: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Set version output + id: vars + run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v' + + - name: Build and push Docker image + if: "contains(github.ref, 'refs/heads/master')" + run: | + echo ${REGISTRY_PASSWORD} | docker login -u ${REGISTRY_USERNAME} --password-stdin quay.io + DOCKER_TAG=${{ steps.vars.outputs.tag }} make docker push + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 06ad672..cd064f2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -41,6 +41,27 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + docker: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Set version output + id: vars + run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v' + + - name: Build and push Docker image + if: "contains(github.ref, 'refs/heads/master')" + run: | + echo ${REGISTRY_PASSWORD} | docker login -u ${REGISTRY_USERNAME} --password-stdin quay.io + DOCKER_TAG=${{ steps.vars.outputs.tag }} make docker push + DOCKER_TAG=latest make push + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + homebrew: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..28cf172 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.14.4-alpine AS builder + +RUN apk add --update --no-cache ca-certificates bash make gcc musl-dev git openssh wget curl + +WORKDIR /go/src/terraform-docs + +COPY go.mod . +COPY go.sum . +RUN go mod download + +COPY . . +RUN make build + +################ + +FROM alpine:3.12.0 + +RUN apk --no-cache add ca-certificates + +COPY --from=builder /go/src/terraform-docs/bin/linux-amd64/terraform-docs /usr/local/bin/ + +ENTRYPOINT ["terraform-docs"] diff --git a/Makefile b/Makefile index f3baf9d..7762c2e 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,11 @@ GORUN ?= GOOS=$(GOOS) GOARCH=$(GOARCH) go run GOIMPORTS_LOCAL_ARG := -local github.com/terraform-docs/terraform-docs +# Docker variables +DEFAULT_TAG ?= $(shell echo "$(VERSION)" | tr -d 'v') +DOCKER_IMAGE := quay.io/$(VENDOR)/$(NAME) +DOCKER_TAG ?= $(DEFAULT_TAG) + # Binary versions GITCHGLOG_VERSION := 0.9.1 GOLANGCI_VERSION := v1.23.7 @@ -95,6 +100,16 @@ build-all: clean ## Build binary for all OS/ARCH @ $(MAKE) --no-print-directory log-$@ @ ./scripts/build/build-all-osarch.sh "$(BUILD_DIR)" "$(NAME)" "$(VERSION)" "$(GOOS)" "$(GOARCH)" $(GOLDFLAGS) +.PHONY: docker +docker: ## Build Docker image + @ $(MAKE) --no-print-directory log-$@ + docker build --pull --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --file Dockerfile . + +.PHONY: push +push: ## Push Docker image + @ $(MAKE) --no-print-directory log-$@ + docker push $(DOCKER_IMAGE):$(DOCKER_TAG) + .PHONY: docs docs: ## Generate document of formatter commands @ $(MAKE) --no-print-directory log-$@ diff --git a/README.md b/README.md index f2e11cc..fe7a76d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,14 @@ The latest version can be installed using `go get`: GO111MODULE="on" go get github.com/terraform-docs/terraform-docs@v0.9.1 ``` +**NOTE:** please use the latest go to do this, we use 1.14 but ideally go 1.13.5 or greater. + +This will put `terraform-docs` in `$(go env GOPATH)/bin`. If you encounter the error `terraform-docs: command not found` after installation then you may need to either add that directory to your `$PATH` as shown [here](https://golang.org/doc/code.html#GOPATH) or do a manual installation by cloning the repo and run `make build` from the repository which will put `terraform-docs` in: + +```bash +$(go env GOPATH)/src/github.com/terraform-docs/terraform-docs/bin/$(uname | tr '[:upper:]' '[:lower:]')-amd64/terraform-docs +``` + If you are a Mac OS X user, you can use [Homebrew](https://brew.sh): ``` bash @@ -46,12 +54,10 @@ Windows users can install using [Chocolatey](https://www.chocolatey.org): choco install terraform-docs ``` -**NOTE:** please use the latest go to do this, we use 1.14 but ideally go 1.13.5 or greater. - -This will put `terraform-docs` in `$(go env GOPATH)/bin`. If you encounter the error `terraform-docs: command not found` after installation then you may need to either add that directory to your `$PATH` as shown [here](https://golang.org/doc/code.html#GOPATH) or do a manual installation by cloning the repo and run `make build` from the repository which will put `terraform-docs` in: +Alternatively you also can run `terraform-docs` as a container: ```bash -$(go env GOPATH)/src/github.com/terraform-docs/terraform-docs/bin/$(uname | tr '[:upper:]' '[:lower:]')-amd64/terraform-docs +docker run quay.io/terraform-docs/terraform-docs:0.9.1 ``` Stable binaries are also available on the [releases](https://github.com/terraform-docs/terraform-docs/releases) page. To install, download the binary for your platform from "Assets" and place this into your `$PATH`: @@ -87,7 +93,7 @@ terraform-docs completion zsh > /usr/local/share/zsh/site-functions/_terraform-d autoload -U compinit && compinit ``` -To make this change permenant, the above commands can be added to your `~/.profile` file. +To make this change permanent, the above commands can be added to your `~/.profile` file. ## Documentation diff --git a/scripts/release/release.sh b/scripts/release/release.sh index 401d29b..1ce9d94 100755 --- a/scripts/release/release.sh +++ b/scripts/release/release.sh @@ -52,12 +52,12 @@ function getClosestVersion() { fi break done - echo "$tag" + echo "$tag" | sed 's/^v//' } CLOSEST_VERSION=$(getClosestVersion) # Bump the released version in README and version.go -sed -i -E 's|'${CLOSEST_VERSION}'|v'${RELEASE_VERSION}'|g' README.md +sed -i -E 's|'${CLOSEST_VERSION}'|'${RELEASE_VERSION}'|g' README.md sed -i -E 's|v'${RELEASE_VERSION}'-alpha|v'${RELEASE_VERSION}'|g' internal/version/version.go # Commit changes