github.com/wuhuizuo/gomplate@v3.5.0+incompatible/docs/content/installing.md (about) 1 --- 2 title: Installing 3 weight: 10 4 menu: main 5 --- 6 7 ## macOS with homebrew 8 9 The simplest method for macOS is to use homebrew: 10 11 ```console 12 $ brew install gomplate 13 ... 14 ``` 15 16 ## Alpine Linux 17 18 `gomplate` is available in Alpine's `community` repository. 19 20 ```console 21 $ apk add --no-cache gomplate 22 ... 23 ``` 24 25 _Note: the Alpine version of gomplate may lag behind the latest release of gomplate._ 26 27 ## use with Docker 28 29 A simple way to get started is with one of the [hairyhenderson/gomplate][] Docker images. Images containing [`slim` binaries](#slim-binaries) are tagged as `:slim` or `:vX.Y.Z-slim`. 30 31 ```console 32 $ docker run hairyhenderson/gomplate --version 33 ``` 34 35 Of course, there are some drawbacks - any files to be used for [datasources][] 36 must be mounted and any environment variables to be used must be passed through: 37 38 ```console 39 $ echo 'My voice is my {{.Env.THING}}. {{(datasource "vault").value}}' \ 40 | docker run -i -e THING=passport -v /home/me/.vault-token:/root/.vault-token hairyhenderson/gomplate -d vault=vault:///secret/sneakers -f - 41 My voice is my passport. Verify me. 42 ``` 43 44 It can be pretty awkward to always type `docker run hairyhenderson/gomplate`, 45 so this can be made simpler with a shell alias: 46 47 ```console 48 $ alias gomplate=docker run hairyhenderson/gomplate 49 $ gomplate --version 50 gomplate version 1.2.3 51 ``` 52 53 ### use inside a container 54 55 `gomplate` is often used inside Docker containers. When building images with Docker 17.05 or higher, you can use [multi-stage builds][] to easily include the `gomplate` binary in your container images. 56 57 Use the `COPY` instruction's `--from` flag to accomplish this: 58 59 ```Dockerfile 60 ... 61 COPY --from=hairyhenderson/gomplate:v2.5.0-slim /gomplate /bin/gomplate 62 ``` 63 64 Now, `gomplate` will be available in the `/bin` directory inside the container image. 65 66 Note that when using `gomplate` with HTTPS-based datasources, you will likely need to install the `ca-certificates` package for your base distribution. Here's an example when using the [`alpine`](https://hub.docker.com/_alpine) base image: 67 68 ```Dockerfile 69 FROM alpine 70 71 COPY --from=hairyhenderson/gomplate:v2.5.0-slim /gomplate /bin/gomplate 72 RUN apk add --no-cache ca-certificates 73 ``` 74 75 ## manual install 76 77 1. Get the latest `gomplate` for your platform from the [releases][] page 78 - if available, you may want to download the [`-slim` variant](#slim-binaries) 79 2. Store the downloaded binary somewhere in your path as `gomplate` (or `gomplate.exe` 80 on Windows) 81 3. Make sure it's executable (on Linux/macOS) 82 3. Test it out with `gomplate --help`! 83 84 In other words: 85 86 ```console 87 $ curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/<version>/gomplate_<os>-<arch> 88 $ chmod 755 /usr/local/bin/gomplate 89 $ gomplate --help 90 ... 91 ``` 92 93 ## install with `go get` 94 95 If you're a Go user already, sometimes it's faster to just use `go get` to install `gomplate`: 96 97 ```console 98 $ go get github.com/hairyhenderson/gomplate/cmd/gomplate 99 $ gomplate --help 100 ... 101 ``` 102 103 ## install with `npm` 104 105 For some users, especially Node.js developers, using `npm` may be a natural fit. 106 Even though `gomplate` is written in Go and not Node.js, it can still be installed 107 with `npm`: 108 109 ```console 110 $ npm install -g gomplate 111 ... 112 ``` 113 114 ## Slim binaries 115 116 As a convenience, self-extracting compressed `gomplate` binaries are available from the [releases][] page. These are named with `-slim` as a suffix (or `-slim.exe`). They are compressed with [UPX][]. 117 118 Generally, these binaries are ~5x smaller than the regular ones, but are otherwise exactly the same. 119 120 There are a few reasons that a regular binary is also distributed: 121 - UPX lacks support for some platforms 122 - there's a very slight chance that the slim binary could exhibit some form of bug related to being compressed 123 - there could be environments where self-extracting compressed executables are disallowed 124 125 [releases]: https://github.com/hairyhenderson/gomplate/releases 126 [UPX]: https://upx.github.io/ 127 [multi-stage builds]: https://docs.docker.com/develop/develop-images/multistage-build/ 128 [hairyhenderson/gomplate]: https://hub.docker.com/r/hairyhenderson/gomplate/tags/