From d95bfe020e0c72df368b4368a4bf61d95eb4416c Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Wed, 10 Apr 2019 13:43:12 +0100 Subject: [PATCH] Dockerfile (#269) Provide docker images for go-toml tools. Ref: https://github.com/pelletier/go-toml/pull/267 --- .circleci/config.yml | 25 +++++++++++++++++++++++++ .dockerignore | 2 ++ .gitignore | 3 +++ Dockerfile | 10 ++++++++++ README.md | 17 +++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.circleci/config.yml b/.circleci/config.yml index a0ef2d7..92254c0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -88,6 +88,28 @@ jobs: command: | curl https://codecov.io/bash > codecov.sh bash codecov.sh -v + docker: + docker: + - image: "circleci/golang:1.12" + steps: + - checkout + - setup_remote_docker: + docker_layer_caching: true + - run: docker build -t pelletier/go-toml:$CIRCLE_SHA1 . + - run: docker login -u $DOCKER_USER -p $DOCKER_PASS + - run: + name: "Publish docker image" + command: | + IMAGE_NAME="pelletier/go-toml" + IMAGE_SHA_TAG="${IMAGE_NAME}:$CIRCLE_SHA1" + if [ "${CIRCLE_BRANCH}" = "master" ]; then + docker tag ${IMAGE_SHA_TAG} ${IMAGE_NAME}:latest + docker push ${IMAGE_NAME}:latest + fi + if [ "${CIRCLE_TAG}" != "" ]; then + docker tag ${IMAGE_SHA_TAG} ${IMAGE_NAME}:${CIRCLE_TAG} + docker push ${IMAGE_NAME}:${CIRCLE_TAG} + fi workflows: version: 2.1 @@ -138,3 +160,6 @@ workflows: requires: - go1_11 - go1_12 + - docker: + requires: + - codecov diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7b58834 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +cmd/tomll/tomll +cmd/tomljson/tomljson diff --git a/.gitignore b/.gitignore index 99e38bb..e6ba63a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ test_program/test_program_bin fuzz/ +cmd/tomll/tomll +cmd/tomljson/tomljson +cmd/tomltestgen/tomltestgen diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f439d4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.12-alpine3.9 as builder +WORKDIR /go/src/github.com/pelletier/go-toml +COPY . . +ENV CGO_ENABLED=0 +ENV GOOS=linux +RUN go install ./... + +FROM scratch +COPY --from=builder /go/bin/tomll /usr/bin/tomll +COPY --from=builder /go/bin/tomljson /usr/bin/tomljson diff --git a/README.md b/README.md index 031a27a..f0311b9 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,23 @@ Go-toml provides two handy command line tools: tomljson --help ``` +### Docker image + +Those tools are also availble as a Docker image from +[dockerhub](https://hub.docker.com/r/pelletier/go-toml). For example, to +use `tomljson`: + +``` +docker run -v $PWD:/workdir pelletier/go-toml tomljson /workdir/example.toml +``` + +Only master (`latest`) and tagged versions are published to dockerhub. You +can build your own image as usual: + +``` +docker build -t go-toml . +``` + ## Contribute Feel free to report bugs and patches using GitHub's pull requests system on