├── .gitignore ├── CHANGELOG.md ├── Dockerfile.erb ├── LICENSE-2.0.txt ├── README.md ├── README.md.erb ├── Rakefile ├── agent-bootstrapper-logback-include.xml ├── agent-launcher-logback-include.xml ├── agent-logback-include.xml └── docker-entrypoint.sh.erb /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .idea 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Docker GoCD agent 18.11.0 2 | 3 | * Updated to use GoCD version 18.10.0 4 | 5 | # Docker GoCD agent 18.11.0 6 | 7 | * Updated to use GoCD version 18.10.0 8 | * Removed alpine 3.5 agent image 9 | * Introduced fedora 28 and 29 based docker agent images 10 | 11 | # Docker GoCD agent 18.10.0 12 | 13 | * Updated to use GoCD version 18.10.0 14 | 15 | # Docker GoCD agent 18.9.0 16 | 17 | * Updated to use GoCD version 18.9.0 18 | * Removed ubuntu 12.04 agent image 19 | 20 | # Docker GoCD agent 18.8.0 21 | 22 | * Updated to use GoCD version 18.8.0 23 | * Introduced an alpine 3.8 based image 24 | * Introduced an Ubuntu 18.04 based image 25 | 26 | # Docker GoCD agent 18.7.0 27 | 28 | * Updated to use GoCD version 18.7.0 29 | 30 | # Docker GoCD agent 18.6.0 31 | 32 | * Updated to use GoCD version 18.6.0 33 | 34 | # Docker GoCD agent 18.5.0 35 | 36 | * Updated to use GoCD version 18.5.0 37 | 38 | # Docker GoCD agent 18.4.0 39 | 40 | * Updated to use GoCD version 18.4.0 41 | 42 | # Docker GoCD agent 18.3.0 43 | 44 | * [b8b8672](https://github.com/gocd/docker-gocd-agent/commit/b8b8672) - Add GoCD Debian 9 Agent image. 45 | 46 | # Docker GoCD agent 18.2.0 47 | 48 | * [76b9abb](https://github.com/gocd/docker-gocd-agent/commit/76b9abb656be905be3837acf7890e8b891370476) - Add GoCD Docker In Docker Agent based on the official docker:dind image 49 | 50 | # Docker GoCD agent 18.1.0 51 | 52 | * [802c7b0](https://github.com/gocd/docker-gocd-agent/commit/802c7b04db0d6badc7608a6e7136bd6c71aeb0d7) - Add docker gocd agent alpine 3.7. 53 | 54 | # Docker GoCD agent 17.12.0 55 | 56 | * [#46](https://github.com/gocd/docker-gocd-server/issues/46) - add support for custom entry-point scripts on startup. Any executables volume mounted in `/docker-entrypoint.d` will be executed before starting the GoCD server. This will allow users to perform initialization when running the container, or building images that derive from the official GoCD docker agent images. 57 | 58 | # Docker GoCD agent 17.11.0 59 | 60 | * [63e0ee9](https://github.com/gocd/docker-gocd-agent/commit/63e0ee9e61d700bac614ea58340d3fa730f29a42) - Move to using logback for writing logs to `STDOUT` 61 | 62 | # Docker GoCD agent 17.10.0 63 | 64 | * [be41207](https://github.com/gocd/docker-gocd-agent/commit/be412073742ea08d14d3b655e0aad01e6ec6a8f2) Allow users to specify `uid` and `gid` as build args while building a docker image. 65 | * [e1f4788](https://github.com/gocd/docker-gocd-agent/commit/e1f47886945e88b4cee07103935311833fb16087) Remove the volume instruction for godata directory. Fix for https://github.com/gocd/docker-gocd-server/issues/25 66 | 67 | # Docker GoCD agent 17.9.0 68 | 69 | * log agent output and logs to `STDOUT` in addition to writing logs to log files, so you can now watch all agent logs using `docker logs`. 70 | 71 | # Docker GoCD agent 17.8.0 72 | 73 | * [dc49b6d](https://github.com/gocd/docker-gocd-agent/commit/dc49b6df3856ebf91ae59562e42968ecca942b93) Create slimmer agent images by deleting the downloaded zip after extraction. 74 | 75 | # Docker GoCD agent 17.7.0 76 | 77 | No changes. 78 | 79 | # Docker GoCD agent 17.6.0 80 | 81 | No changes. 82 | 83 | # Docker GoCD agent 17.5.0 84 | 85 | No changes. 86 | 87 | # Docker GoCD agent 17.4.0 88 | 89 | ## Bug Fixes 90 | 91 | * [27b8772](https://github.com/gocd/docker-gocd-agent/commit/27b8772) Remove `/home/go` from the volume instruction. This makes the `/home/go` directory writable by `go` user. 92 | * [44b592f](https://github.com/gocd/docker-gocd-agent/commit/44b592f) Create home directory `/home/go` for docker agent images based on debian. 93 | -------------------------------------------------------------------------------- /Dockerfile.erb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 ThoughtWorks, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | ############################################################################################### 16 | # This file is autogenerated by the repository at https://github.com/gocd/docker-gocd-agent. 17 | # Please file any issues or PRs at https://github.com/gocd/docker-gocd-agent 18 | ############################################################################################### 19 | 20 | FROM <%= distro %>:<%= release_name %> 21 | MAINTAINER GoCD 22 | 23 | LABEL gocd.version="<%= gocd_version %>" \ 24 | description="GoCD agent based on <%= distro %> version <%= version %>" \ 25 | maintainer="GoCD " \ 26 | gocd.full.version="<%= gocd_full_version %>" \ 27 | gocd.git.sha="<%= gocd_git_sha %>" 28 | 29 | <% add_files.each do |file, meta| -%> 30 | ADD <%= meta[:url] %> <%= file %> 31 | <% end %> 32 | 33 | # force encoding 34 | ENV LANG en_US.UTF-8 35 | ENV LANGUAGE en_US:en 36 | ENV LC_ALL en_US.UTF-8 37 | <% unless ['docker', 'alpine'].include?(distro) -%> 38 | ENV GO_JAVA_HOME="/go-agent/jre" 39 | <% end-%> 40 | 41 | ARG UID=1000 42 | ARG GID=1000 43 | 44 | RUN \ 45 | <% unless add_files.empty? -%> 46 | # add mode and permissions for files we added above 47 | <%= add_files.collect {|file, meta| ["chmod #{meta[:mode]} #{file}", "chown #{meta[:owner]}:#{meta[:group]} #{file}"]}.flatten.join(" && \\\n ") %> && \ 48 | <% end -%> 49 | # add our user and group first to make sure their IDs get assigned consistently, 50 | # regardless of whatever dependencies get added 51 | <%= create_user_and_group.join(" && \\ \n ") -%> && \ 52 | <%= before_install.join(" && \\\n ") -%> && \ 53 | # download the zip file 54 | curl --fail --location --silent --show-error "<%= download_url %>" > /tmp/go-agent.zip && \ 55 | # unzip the zip file into /go-agent, after stripping the first path prefix 56 | unzip /tmp/go-agent.zip -d / && \ 57 | <% if ['docker', 'alpine'].include?(distro) -%> 58 | mv go-agent-<%= gocd_version %> /go-agent/ && \ 59 | <% else -%> 60 | mv go-agent-<%= gocd_version %>/** /go-agent/ && \ 61 | <% end -%> 62 | rm /tmp/go-agent.zip && \ 63 | mkdir -p /docker-entrypoint.d 64 | 65 | # ensure that logs are printed to console output 66 | COPY agent-bootstrapper-logback-include.xml agent-launcher-logback-include.xml agent-logback-include.xml /go-agent/config/ 67 | 68 | ADD docker-entrypoint.sh / 69 | 70 | ENTRYPOINT ["/docker-entrypoint.sh"] 71 | -------------------------------------------------------------------------------- /LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoCD Agent Docker image 2 | 3 | This repository is the parent repository for the following docker images 4 | 5 | * [gocd/gocd-agent-alpine-3.6](https://github.com/gocd/docker-gocd-agent-alpine-3.6) 6 | * [gocd/gocd-agent-alpine-3.7](https://github.com/gocd/docker-gocd-agent-alpine-3.7) 7 | * [gocd/gocd-agent-alpine-3.8](https://github.com/gocd/docker-gocd-agent-alpine-3.8) 8 | * [gocd/gocd-agent-alpine-3.9](https://github.com/gocd/docker-gocd-agent-alpine-3.9) 9 | * [gocd/gocd-agent-centos-6](https://github.com/gocd/docker-gocd-agent-centos-6) 10 | * [gocd/gocd-agent-centos-7](https://github.com/gocd/docker-gocd-agent-centos-7) 11 | * [gocd/gocd-agent-debian-8](https://github.com/gocd/docker-gocd-agent-debian-8) 12 | * [gocd/gocd-agent-debian-9](https://github.com/gocd/docker-gocd-agent-debian-9) 13 | * [gocd/gocd-agent-docker-dind](https://github.com/gocd/gocd-agent-docker-dind) 14 | * [gocd/gocd-agent-ubuntu-14.04](https://github.com/gocd/docker-gocd-agent-ubuntu-14.04) 15 | * [gocd/gocd-agent-ubuntu-16.04](https://github.com/gocd/docker-gocd-agent-ubuntu-16.04) 16 | * [gocd/gocd-agent-ubuntu-18.04](https://github.com/gocd/docker-gocd-agent-ubuntu-18.04) 17 | * [gocd/docker-gocd-agent-fedora-28](https://github.com/gocd/docker-gocd-agent-fedora-28) 18 | * [gocd/docker-gocd-agent-fedora-29](https://github.com/gocd/docker-gocd-agent-fedora-29) 19 | 20 | # Usage 21 | *The build process uses the `Rakefile` to build different tasks. There are three tasks that 22 | you could build: __all images__, __specific image__, and __publish__ the docker images.* 23 | 24 | The URL for environment variable `GOCD_AGENT_DOWNLOAD_URL` is under the Zip tab from 25 | this [`download`][0] webpage. 26 | 27 | ## 1. Building all images 28 | 29 | ```bash 30 | GOCD_VERSION=X.Y.Z \ 31 | GOCD_AGENT_DOWNLOAD_URL=https://download.gocd.io/binaries/X.Y.Z-PPPP/generic/go-agent-X.Y.Z-PPPP.zip \ 32 | rake build_image [--trace] 33 | ``` 34 | 35 | ## 2. Building a specific image 36 | **List all targets** 37 | ```bash 38 | GOCD_VERSION=X.Y.Z \ 39 | GOCD_AGENT_DOWNLOAD_URL=https://download.gocd.io/binaries/X.Y.Z-PPPP/generic/go-agent-X.Y.Z-PPPP.zip \ 40 | rake -T build_image 41 | ``` 42 | 43 | **Build a specific image, ubuntu 16.04, gocd version 17.3.0** 44 | ```bash 45 | GOCD_VERSION=17.3.0 \ 46 | GOCD_AGENT_DOWNLOAD_URL=https://download.gocd.io/binaries/17.3.0-4704/generic/go-agent-17.3.0-4704.zip \ 47 | rake gocd-agent-ubuntu-16.04:build_image 48 | ``` 49 | 50 | ## 3. Publishing all docker images 51 | ```bash 52 | GOCD_VERSION=X.Y.Z GOCD_AGENT_DOWNLOAD_URL=https://download.gocd.io/binaries/X.Y.Z-PPPP/generic/go-agent-X.Y.Z-PPPP.zip 53 | rake publish [--trace] 54 | ``` 55 | **_Note:_** *_Image will be removed from machine post push. To disable auto cleanup add env `CLEAN_IMAGES=false`_* 56 | 57 | 58 | # License 59 | 60 | ```plain 61 | Copyright 2018 ThoughtWorks, Inc. 62 | 63 | Licensed under the Apache License, Version 2.0 (the "License"); 64 | you may not use this file except in compliance with the License. 65 | You may obtain a copy of the License at 66 | 67 | http://www.apache.org/licenses/LICENSE-2.0 68 | 69 | Unless required by applicable law or agreed to in writing, software 70 | distributed under the License is distributed on an "AS IS" BASIS, 71 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 72 | See the License for the specific language governing permissions and 73 | limitations under the License. 74 | ``` 75 | 76 | [0]: https://www.gocd.io/download/ 77 | -------------------------------------------------------------------------------- /README.md.erb: -------------------------------------------------------------------------------- 1 | # GoCD Agent Docker image 2 | 3 | [GoCD agent](https://www.gocd.io) docker image based on <%= distro %> <%= version %>. 4 | 5 | <%- if about_to_eol -%> 6 | # This image is deprecated 7 | 8 | > **Note**: This image is now deprecated and will be sunset on **<%= eol_date.strftime('%b %d, %Y') %>**. 9 | <%- end -%> 10 | 11 | # Issues, feedback? 12 | 13 | Please make sure to log them at https://github.com/gocd/docker-gocd-agent. 14 | 15 | # Changelog 16 | 17 | Please checkout the changes made every release to the agent images at https://github.com/gocd/docker-gocd-agent/blob/master/CHANGELOG.md 18 | 19 | # Usage 20 | 21 | Start the container with this: 22 | 23 | ``` 24 | docker run <%= needs_privileged_mode ? "--privileged " : "" %>-d -e GO_SERVER_URL=... gocd/<%= image_name %>:<%= image_tag %> 25 | ``` 26 | 27 | **Note:** Please make sure to *always* provide the version. We do not publish the `latest` tag. And we don't intend to. 28 | 29 | This will start the GoCD agent and connect it the GoCD server specified by `GO_SERVER_URL`. 30 | 31 | > **Note**: The `GO_SERVER_URL` must be an HTTPS url and end with `/go`, for e.g. `https://ip.add.re.ss:8154/go` 32 | 33 | ## Usage with docker GoCD server 34 | 35 | If you have a [gocd-server container](https://hub.docker.com/r/gocd/gocd-server/) running and it's named `angry_feynman`, you can connect a gocd-agent container to it by doing: 36 | 37 | ``` 38 | docker run <%= needs_privileged_mode ? "--privileged " : "" %>-d -e GO_SERVER_URL=https://$(docker inspect --format='{{(index (index .NetworkSettings.IPAddress))}}' angry_feynman):8154/go gocd/<%= image_name %>:<%= image_tag %> 39 | ``` 40 | OR 41 | 42 | If the docker container running the gocd server has ports mapped to the host, 43 | 44 | ``` 45 | docker run <%= needs_privileged_mode ? "--privileged " : "" %>-d -e GO_SERVER_URL=https://:$(docker inspect --format='{{(index (index .NetworkSettings.Ports "8154/tcp") 0).HostPort}}' angry_feynman)/go gocd/<%= image_name %>:<%= image_tag %> 46 | ``` 47 | 48 | # Available configuration options 49 | 50 | ## Auto-registering the agents 51 | 52 | ``` 53 | docker run <%= needs_privileged_mode ? "--privileged " : "" %>-d \ 54 | -e AGENT_AUTO_REGISTER_KEY=... \ 55 | -e AGENT_AUTO_REGISTER_RESOURCES=... \ 56 | -e AGENT_AUTO_REGISTER_ENVIRONMENTS=... \ 57 | -e AGENT_AUTO_REGISTER_HOSTNAME=... \ 58 | gocd/<%= image_name %>:<%= image_tag %> 59 | ``` 60 | 61 | If the `AGENT_AUTO_REGISTER_*` variables are provided (we recommend that you do), then the agent will be automatically approved by the server. See the [auto registration docs](https://docs.gocd.io/current/advanced_usage/agent_auto_register.html) on the GoCD website. 62 | 63 | <% unless needs_privileged_mode %> 64 | ## Usage with docker and swarm elastic agent plugins 65 | 66 | This image will work well with the [docker elastic agent plugin](https://github.com/gocd-contrib/docker-elastic-agents) and the [docker swarm elastic agent plugin](https://github.com/gocd-contrib/docker-swarm-elastic-agents). No special configuration would be needed. 67 | <% end %> 68 | ## Mounting volumes 69 | 70 | The GoCD agent will store all configuration, logs and perform builds in `/godata`. If you'd like to provide secure credentials like SSH private keys among other things, you can mount `/home/go`. 71 | 72 | ``` 73 | docker run <%= needs_privileged_mode ? "--privileged " : "" %>-v /path/to/godata:/godata -v /path/to/home-dir:/home/go gocd/<%= image_name %>:<%= image_tag %> 74 | ``` 75 | 76 | > **Note:** Ensure that `/path/to/home-dir` and `/path/to/godata` is accessible by the `go` user in container (`go` user - uid 1000). 77 | 78 | ## Tweaking JVM options (memory, heap etc) 79 | 80 | JVM options can be tweaked using the environment variable `GO_AGENT_SYSTEM_PROPERTIES`. 81 | 82 | ``` 83 | docker run <%= needs_privileged_mode ? "--privileged " : "" %>-e GO_AGENT_SYSTEM_PROPERTIES="-Dfoo=bar" gocd/<%= image_name %>:<%= image_tag %> 84 | ``` 85 | 86 | # Under the hood 87 | 88 | The GoCD server runs as the `go` user, the location of the various directories is: 89 | 90 | | Directory | Description | 91 | |---------------------|----------------------------------------------------------------------------------| 92 | | `/godata/config` | the directory where the GoCD configuration is store | 93 | | `/godata/pipelines` | the directory where the agent will run builds | 94 | | `/godata/logs` | the directory where GoCD logs will be written out to | 95 | | `/home/go` | the home directory for the GoCD server | 96 | 97 | <% unless needs_privileged_mode %> 98 | ## Running docker and docker-compose in your jobs 99 | 100 | To be able to run the `docker` and `docker-compose` commands inside your jobs, you will need to share the docker socket as a volume from your host which is pretty classic. 101 | 102 | In this case, as the docker deamon will be the one mounting the volumes you define, the path to the files you will want to mount (basically inside `/godata/pipelines`) need to be the same so that the docker deamon (which is running on the host) can find the files. 103 | 104 | If you run several agents container, you will need to overwrite the `VOLUME_DIR` environment variable to have a different path for your `/godata` for each of your gocd agent containers (to avoid issues). For example, if the volume on your host for the first container is `/go-agent1/godata`, you will set the `VOLUME_DIR` environment data on your container to `/go-agent1/godata` and the `docker-entrypoint.sh` script will automatically manage it and make sure the agent stores its configuration, logs and pipelines there. 105 | <% end %> 106 | 107 | # Troubleshooting 108 | 109 | ## The GoCD agent does not connect to the server 110 | 111 | - Check if the docker container is running `docker ps -a` 112 | - Check the STDOUT to see if there is any output that indicates failures `docker logs CONTAINER_ID` 113 | - Check the agent logs `docker exec -it CONTAINER_ID /bin/bash`, then run `less /godata/logs/*.log` inside the container. 114 | 115 | # Bugs with Docker Agent Images 17.3.0 116 | 117 | * Anyone using our docker agent image as the base image for your customized image, and writing to `/home/go` as part of your Dockerfile, these changes in `/home/go` don't persist while you start the container with your custom image. 118 | A fix has been applied [here](https://github.com/gocd/docker-gocd-agent/commit/27b8772) and will be available for subsequent releases of the docker images. 119 | 120 | 121 | # License 122 | 123 | ```plain 124 | Copyright 2018 ThoughtWorks, Inc. 125 | 126 | Licensed under the Apache License, Version 2.0 (the "License"); 127 | you may not use this file except in compliance with the License. 128 | You may obtain a copy of the License at 129 | 130 | http://www.apache.org/licenses/LICENSE-2.0 131 | 132 | Unless required by applicable law or agreed to in writing, software 133 | distributed under the License is distributed on an "AS IS" BASIS, 134 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135 | See the License for the specific language governing permissions and 136 | limitations under the License. 137 | ``` 138 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Copyright 2019 ThoughtWorks, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'erb' 16 | require 'open-uri' 17 | require 'json' 18 | 19 | def versionFile(name) 20 | version_file_location = ENV["VERSION_FILE_LOCATION"] || 'version.json' 21 | JSON.parse(File.read(version_file_location))[name] if File.file?(version_file_location) 22 | end 23 | 24 | def get_var(name) 25 | value = ENV[name] 26 | raise "\e[1;31m[ERROR]\e[0m Environment #{name} not specified!" if value.to_s.strip.empty? 27 | value 28 | end 29 | 30 | class Docker 31 | def self.login 32 | token = ENV["TOKEN"] 33 | if token 34 | FileUtils.mkdir_p "#{Dir.home}/.docker" 35 | File.open("#{Dir.home}/.docker/config.json", "w") do |f| 36 | f.write({:auths => {"https://index.docker.io/v1/" => {:auth => token}}}.to_json) 37 | end 38 | else 39 | puts "\e[1;33m[WARN]\e[0m Skipping docker login as environment variable TOKEN is not specified." 40 | end 41 | end 42 | end 43 | 44 | gocd_full_version = versionFile('go_full_version') || get_var('GOCD_FULL_VERSION') 45 | gocd_version = versionFile('go_version') || get_var('GOCD_VERSION') 46 | gocd_git_sha = versionFile('git_sha') || get_var('GOCD_GIT_SHA') 47 | remove_image_post_push = ENV['CLEAN_IMAGES'] || true 48 | is_stable_release = ENV['GOCD_STABLE_RELEASE'] == "true" || false 49 | download_url = ENV['GOCD_AGENT_DOWNLOAD_URL'] || "https://download.gocd.org#{is_stable_release ? "/" : "/experimental/" }binaries/#{gocd_full_version}/generic/go-agent-#{gocd_full_version}.zip" 50 | 51 | # Perform docker login if token is specified 52 | Docker.login 53 | 54 | ROOT_DIR = Dir.pwd 55 | 56 | def tini_assets 57 | @tini_assets ||= JSON.parse(open('https://api.github.com/repos/krallin/tini/releases/latest').read)['assets'] 58 | end 59 | 60 | def gosu_assets 61 | @gosu_assets ||= JSON.parse(open('https://api.github.com/repos/tianon/gosu/releases/latest').read)['assets'] 62 | end 63 | 64 | def tini_url 65 | tini_assets.find {|asset| asset['browser_download_url'] =~ /tini-static-amd64$/}['browser_download_url'] 66 | end 67 | 68 | def gosu_url 69 | gosu_assets.find {|asset| asset['browser_download_url'] =~ /gosu-amd64$/}['browser_download_url'] 70 | end 71 | 72 | def adoptopenjdk_assets 73 | @adoptopenjdk_assets ||= JSON.parse(open('https://api.github.com/repos/AdoptOpenJDK/openjdk12-binaries/releases/latest').read)['assets'] 74 | end 75 | 76 | def adoptopenjre_url 77 | adoptopenjdk_assets.find {|asset| asset['name'] =~ /jre_x64_linux_hotspot.*.tar.gz/ }['browser_download_url'] 78 | end 79 | 80 | def install_java 81 | [ 82 | "curl --fail --location --silent --show-error #{adoptopenjre_url} > adoptopenjre.tar.gz", 83 | 'mkdir -p /go-agent/jre', 84 | 'tar -xf adoptopenjre.tar.gz -C /go-agent/jre --strip 1', 85 | 'rm -rf adoptopenjre.tar.gz' 86 | ] 87 | end 88 | 89 | def yum_install_git29 90 | [ 91 | "yum install --assumeyes centos-release-scl", 92 | "yum install --assumeyes rh-git29", 93 | "cp /opt/rh/rh-git29/enable /etc/profile.d/rh-git29.sh" 94 | ] 95 | end 96 | 97 | tini_and_gosu_add_file_meta = { 98 | '/usr/local/sbin/tini' => {url: tini_url, mode: '0755', owner: 'root', group: 'root'}, 99 | '/usr/local/sbin/gosu' => {url: gosu_url, mode: '0755', owner: 'root', group: 'root'} 100 | } 101 | 102 | create_user_and_group_cmd = [ 103 | 'groupadd -g ${GID} go', 104 | 'useradd -u ${UID} -g go -d /home/go -m go' 105 | ] 106 | 107 | maybe_credentials = "#{ENV['GIT_USER']}:#{ENV['GIT_PASSWORD']}@" if ENV['GIT_USER'] && ENV['GIT_PASSWORD'] 108 | 109 | agents = [ 110 | { 111 | distro: 'alpine', 112 | version: '3.6', 113 | release_name: '3.6', 114 | eol_date: '2019-05-01', 115 | continue_to_build: 'true', 116 | add_files: tini_and_gosu_add_file_meta, 117 | create_user_and_group: [ 118 | 'addgroup -g ${GID} go', 119 | 'adduser -D -u ${UID} -s /bin/bash -G go go' 120 | ], 121 | before_install: [ 122 | 'apk --no-cache upgrade', 123 | 'apk add --no-cache nss openjdk8-jre-base git mercurial subversion openssh-client bash curl' 124 | ] 125 | }, 126 | { 127 | distro: 'alpine', 128 | version: '3.7', 129 | release_name: '3.7', 130 | eol_date: '2019-11-01', 131 | add_files: tini_and_gosu_add_file_meta, 132 | create_user_and_group: [ 133 | 'addgroup -g ${GID} go', 134 | 'adduser -D -u ${UID} -s /bin/bash -G go go' 135 | ], 136 | before_install: [ 137 | 'apk --no-cache upgrade', 138 | 'apk add --no-cache nss openjdk8-jre-base git mercurial subversion openssh-client bash curl' 139 | ] 140 | }, 141 | { 142 | distro: 'alpine', 143 | version: '3.8', 144 | release_name: '3.8', 145 | eol_date: '2020-05-01', 146 | add_files: tini_and_gosu_add_file_meta, 147 | create_user_and_group: [ 148 | 'addgroup -g ${GID} go', 149 | 'adduser -D -u ${UID} -s /bin/bash -G go go' 150 | ], 151 | before_install: [ 152 | 'apk --no-cache upgrade', 153 | 'apk add --no-cache nss openjdk8-jre-base git mercurial subversion openssh-client bash curl' 154 | ] 155 | }, 156 | { 157 | distro: 'alpine', 158 | version: '3.9', 159 | release_name: '3.9', 160 | eol_date: '2021-01-01', 161 | add_files: tini_and_gosu_add_file_meta, 162 | create_user_and_group: [ 163 | 'addgroup -g ${GID} go', 164 | 'adduser -D -u ${UID} -s /bin/bash -G go go' 165 | ], 166 | before_install: [ 167 | 'apk --no-cache upgrade', 168 | 'apk add --no-cache nss openjdk8-jre-base git mercurial subversion openssh-client bash curl' 169 | ] 170 | }, 171 | { 172 | distro: 'docker', 173 | version: 'dind', 174 | release_name: 'dind', 175 | eol_date: '2099-01-01', 176 | add_files: tini_and_gosu_add_file_meta, 177 | needs_privileged_mode: true, 178 | repo_url: "https://#{maybe_credentials}github.com/#{ENV['REPO_OWNER'] || 'gocd'}/gocd-agent-docker-dind", 179 | create_user_and_group: [ 180 | 'addgroup -g ${GID} go', 181 | 'adduser -D -u ${UID} -s /bin/bash -G go go', 182 | 'addgroup go root' 183 | ], 184 | before_install: [ 185 | 'apk --no-cache upgrade', 186 | 'apk add --no-cache nss openjdk8-jre-base git mercurial subversion openssh-client bash curl' 187 | ], 188 | setup_commands: [ 189 | 'sh -c "$(which dind) dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375" > /usr/local/bin/nohup.out 2>&1 &' 190 | ] 191 | }, 192 | { 193 | distro: 'debian', 194 | version: '8', 195 | release_name: 'jessie', 196 | eol_date: '2020-06-30', 197 | add_files: tini_and_gosu_add_file_meta, 198 | create_user_and_group: create_user_and_group_cmd, 199 | before_install: [ 200 | 'apt-get update', 201 | 'apt-get install -y git subversion mercurial openssh-client bash unzip curl locales', 202 | 'apt-get autoclean', 203 | 'echo \'en_US.UTF-8 UTF-8\' > /etc/locale.gen && /usr/sbin/locale-gen' 204 | ] + install_java 205 | }, 206 | { 207 | distro: 'debian', 208 | version: '9', 209 | release_name: 'stretch', 210 | eol_date: '2022-06-30', 211 | add_files: tini_and_gosu_add_file_meta, 212 | create_user_and_group: create_user_and_group_cmd, 213 | before_install: [ 214 | 'apt-get update', 215 | 'apt-get install -y git subversion mercurial openssh-client bash unzip curl locales', 216 | 'apt-get autoclean', 217 | 'echo \'en_US.UTF-8 UTF-8\' > /etc/locale.gen && /usr/sbin/locale-gen' 218 | ] + install_java 219 | }, 220 | { 221 | distro: 'ubuntu', 222 | version: '16.04', 223 | release_name: 'xenial', 224 | eol_date: '2021-04-01', 225 | add_files: tini_and_gosu_add_file_meta, 226 | create_user_and_group: create_user_and_group_cmd, 227 | before_install: [ 228 | 'apt-get update', 229 | 'apt-get install -y git subversion mercurial openssh-client bash unzip curl locales', 230 | 'apt-get autoclean', 231 | 'echo \'en_US.UTF-8 UTF-8\' > /etc/locale.gen && /usr/sbin/locale-gen' 232 | ] + install_java 233 | }, 234 | { 235 | distro: 'ubuntu', 236 | version: '18.04', 237 | release_name: 'bionic', 238 | eol_date: '2023-04-01', 239 | add_files: tini_and_gosu_add_file_meta, 240 | create_user_and_group: create_user_and_group_cmd, 241 | before_install: [ 242 | 'apt-get update', 243 | 'apt-get install -y git subversion mercurial openssh-client bash unzip curl locales', 244 | 'apt-get autoclean', 245 | 'echo \'en_US.UTF-8 UTF-8\' > /etc/locale.gen && /usr/sbin/locale-gen' 246 | ] + install_java 247 | }, 248 | { 249 | distro: 'centos', 250 | version: '6', 251 | release_name: '6', 252 | eol_date: '2020-11-01', 253 | add_files: tini_and_gosu_add_file_meta, 254 | create_user_and_group: create_user_and_group_cmd, 255 | before_install: [ 256 | 'yum update -y', 257 | 'yum install -y mercurial subversion openssh-clients bash unzip curl', 258 | ] + yum_install_git29 + install_java + [ 'yum clean all' ] 259 | }, 260 | { 261 | distro: 'centos', 262 | version: '7', 263 | release_name: '7', 264 | eol_date: '2024-06-01', 265 | add_files: tini_and_gosu_add_file_meta, 266 | create_user_and_group: create_user_and_group_cmd, 267 | before_install: [ 268 | 'yum update -y', 269 | 'yum install -y mercurial subversion openssh-clients bash unzip curl', 270 | ] + yum_install_git29 + install_java + [ 'yum clean all' ] 271 | }, 272 | { 273 | distro: 'fedora', 274 | version: '28', 275 | release_name: '28', 276 | continue_to_build: 'true', 277 | eol_date: '2019-06-01', # Fedora has 13 months for EOL 278 | add_files: tini_and_gosu_add_file_meta, 279 | create_user_and_group: create_user_and_group_cmd, 280 | before_install: [ 281 | 'yum update -y', 282 | 'yum install -y git mercurial subversion openssh-clients bash unzip curl', 283 | 'yum clean all' 284 | ] + install_java 285 | }, 286 | { 287 | distro: 'fedora', 288 | version: '29', 289 | release_name: '29', 290 | eol_date: '2019-11-30', # approximate date - 1 year from release date, check when the build fails 291 | add_files: tini_and_gosu_add_file_meta, 292 | create_user_and_group: create_user_and_group_cmd, 293 | before_install: [ 294 | 'yum update -y', 295 | 'yum install -y git mercurial subversion openssh-clients bash unzip curl', 296 | 'yum clean all' 297 | ] + install_java 298 | } 299 | ] 300 | 301 | total_workers = (ENV['GO_JOB_RUN_COUNT'] || '1').to_i 302 | agents_per_worker = (agents.size.to_f / total_workers).ceil 303 | current_worker_index = (ENV['GO_JOB_RUN_INDEX'] || '1').to_i 304 | agents_to_build = agents.each_slice(agents_per_worker).to_a[current_worker_index - 1] 305 | 306 | agents_to_build.each do |image| 307 | distro = image[:distro] 308 | version = image[:version] 309 | release_name = image[:release_name] 310 | image_tag = "v#{gocd_version}" 311 | before_install = image[:before_install] 312 | add_files = image[:add_files] || {} 313 | create_user_and_group = image[:create_user_and_group] || [] 314 | setup_commands = image[:setup_commands] || [] 315 | eol_date = Date.strptime(image[:eol_date], '%Y-%m-%d') 316 | about_to_eol = (eol_date - Date.today) <= 95 317 | needs_privileged_mode = image[:needs_privileged_mode] || false 318 | 319 | if eol_date <= Date.today 320 | raise "The image #{distro}:#{version} is unsupported EOL was #{eol_date}." 321 | end 322 | 323 | if about_to_eol && !image[:continue_to_build] 324 | raise "The image #{distro}:#{version} is supposed to be EOL in #{(eol_date - Date.today).to_i} day(s), on #{eol_date}. Set :continue_to_build option to continue building." 325 | end 326 | 327 | image_name = "gocd-agent-#{distro}-#{version}" 328 | repo_name = "docker-#{image_name}" 329 | dir_name = "build/#{repo_name}" 330 | repo_url = image[:repo_url] || "https://#{maybe_credentials}github.com/#{ENV['REPO_OWNER'] || 'gocd'}/#{repo_name}" 331 | 332 | namespace image_name do 333 | task :clean do 334 | rm_rf dir_name 335 | end 336 | 337 | task :init do 338 | sh(%(git clone --quiet "#{repo_url}" #{dir_name})) 339 | end 340 | 341 | task :create_dockerfile do 342 | docker_template = File.read('Dockerfile.erb') 343 | docker_renderer = ERB.new(docker_template, nil, '-') 344 | File.open("#{dir_name}/Dockerfile", 'w') do |f| 345 | f.puts(docker_renderer.result(binding)) 346 | end 347 | 348 | readme_template = File.read("#{ROOT_DIR}/README.md.erb") 349 | readme_renderer = ERB.new(readme_template, nil, '-') 350 | File.open("#{dir_name}/README.md", 'w') do |f| 351 | f.puts(readme_renderer.result(binding)) 352 | end 353 | 354 | cp "#{ROOT_DIR}/LICENSE-2.0.txt", "#{dir_name}/LICENSE-2.0.txt" 355 | Dir['*-logback-include.xml'].each do |f| 356 | cp f, "#{dir_name}" 357 | end 358 | end 359 | 360 | task :create_entrypoint_script do 361 | docker_template = File.read('docker-entrypoint.sh.erb') 362 | docker_renderer = ERB.new(docker_template, nil, '-') 363 | File.open("#{dir_name}/docker-entrypoint.sh", 'w') do |f| 364 | f.puts(docker_renderer.result(binding)) 365 | end 366 | sh("chmod +x #{dir_name}/docker-entrypoint.sh") 367 | end 368 | 369 | task :build_docker_image do 370 | cd dir_name do 371 | sh("docker build . -t #{image_name}:#{ENV['TAG'] || image_tag}") 372 | end 373 | end 374 | 375 | task :commit_files do 376 | cd dir_name do 377 | sh('git add .') 378 | sh("git commit -m 'Update with GoCD Version #{gocd_version}' --author 'GoCD CI User '") 379 | end 380 | end 381 | 382 | task :create_tag do 383 | cd dir_name do 384 | sh("git tag '#{image_tag}'") 385 | end 386 | end 387 | 388 | task :git_push do 389 | cd dir_name do 390 | sh('git push') 391 | sh('git push --tags') 392 | end 393 | end 394 | 395 | task :docker_push_image_experimental => :build_image do 396 | org = ENV['EXP_ORG'] || 'gocdexperimental' 397 | tag = "v#{gocd_full_version}" 398 | sh("docker tag #{image_name}:#{image_tag} #{org}/#{image_name}:#{tag}") 399 | sh("docker push #{org}/#{image_name}:#{tag}") 400 | sh("docker rmi -f #{org}/#{image_name}:#{tag} #{image_name}:#{image_tag} #{distro}:#{version}") if remove_image_post_push 401 | end 402 | 403 | task :docker_push_image_stable do 404 | org = ENV['ORG'] || 'gocd' 405 | tag = "v#{gocd_full_version}" 406 | experimental_org = ENV['EXP_ORG'] || 'gocdexperimental' 407 | sh("docker pull #{experimental_org}/#{image_name}:v#{gocd_full_version}") 408 | sh("docker tag #{experimental_org}/#{image_name}:v#{gocd_full_version} #{org}/#{image_name}:#{image_tag}") 409 | sh("docker push #{org}/#{image_name}:#{image_tag}") 410 | sh("docker rmi -f #{org}/#{image_name}:#{tag} #{experimental_org}/#{image_name}:v#{gocd_full_version} #{distro}:#{version}") if remove_image_post_push 411 | end 412 | 413 | desc "Publish #{image_name} to dockerhub" 414 | task publish: [:clean, :init, :create_dockerfile, :create_entrypoint_script, :commit_files, :create_tag, :git_push] 415 | 416 | desc "Build #{image_name} image locally" 417 | task build_image: [:clean, :init, :create_dockerfile, :create_entrypoint_script, :build_docker_image] 418 | end 419 | 420 | desc 'Publish all images to dockerhub' 421 | task publish: "#{image_name}:publish" 422 | 423 | desc 'Build all images locally' 424 | task build_image: "#{image_name}:build_image" 425 | 426 | desc "Push all images to experimental" 427 | task docker_push_experimental: "#{image_name}:docker_push_image_experimental" 428 | 429 | desc "Push all images to stable" 430 | task docker_push_stable: "#{image_name}:docker_push_image_stable" 431 | end 432 | -------------------------------------------------------------------------------- /agent-bootstrapper-logback-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | ${gocd.agentBootstrapper.logback.defaultPattern:-%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /agent-launcher-logback-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | ${gocd.agentLauncher.logback.defaultPattern:-%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /agent-logback-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | ${gocd.agent.logback.defaultPattern:-%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /docker-entrypoint.sh.erb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 ThoughtWorks, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | yell() { echo "$0: $*" >&2; } 18 | die() { yell "$*"; exit 111; } 19 | try() { echo "$ $@" 1>&2; "$@" || die "cannot $*"; } 20 | 21 | setup_autoregister_properties_file_for_elastic_agent() { 22 | echo "agent.auto.register.key=${GO_EA_AUTO_REGISTER_KEY}" >> $1 23 | echo "agent.auto.register.environments=${GO_EA_AUTO_REGISTER_ENVIRONMENT}" >> $1 24 | echo "agent.auto.register.elasticAgent.agentId=${GO_EA_AUTO_REGISTER_ELASTIC_AGENT_ID}" >> $1 25 | echo "agent.auto.register.elasticAgent.pluginId=${GO_EA_AUTO_REGISTER_ELASTIC_PLUGIN_ID}" >> $1 26 | echo "agent.auto.register.hostname=${AGENT_AUTO_REGISTER_HOSTNAME}" >> $1 27 | 28 | export GO_SERVER_URL="${GO_EA_SERVER_URL}" 29 | # unset variables, so we don't pollute and leak sensitive stuff to the agent process... 30 | unset GO_EA_AUTO_REGISTER_KEY GO_EA_AUTO_REGISTER_ENVIRONMENT GO_EA_AUTO_REGISTER_ELASTIC_AGENT_ID GO_EA_AUTO_REGISTER_ELASTIC_PLUGIN_ID GO_EA_SERVER_URL AGENT_AUTO_REGISTER_HOSTNAME 31 | } 32 | 33 | setup_autoregister_properties_file_for_normal_agent() { 34 | echo "agent.auto.register.key=${AGENT_AUTO_REGISTER_KEY}" >> $1 35 | echo "agent.auto.register.resources=${AGENT_AUTO_REGISTER_RESOURCES}" >> $1 36 | echo "agent.auto.register.environments=${AGENT_AUTO_REGISTER_ENVIRONMENTS}" >> $1 37 | echo "agent.auto.register.hostname=${AGENT_AUTO_REGISTER_HOSTNAME}" >> $1 38 | 39 | # unset variables, so we don't pollute and leak sensitive stuff to the agent process... 40 | unset AGENT_AUTO_REGISTER_KEY AGENT_AUTO_REGISTER_RESOURCES AGENT_AUTO_REGISTER_ENVIRONMENTS AGENT_AUTO_REGISTER_HOSTNAME 41 | } 42 | 43 | setup_autoregister_properties_file() { 44 | if [ -n "$GO_EA_SERVER_URL" ]; then 45 | setup_autoregister_properties_file_for_elastic_agent "$1" 46 | try chown go:go $1 47 | else 48 | setup_autoregister_properties_file_for_normal_agent "$1" 49 | try chown go:go $1 50 | fi 51 | } 52 | 53 | [ -z "${VOLUME_DIR}" ] && VOLUME_DIR="/godata" 54 | 55 | AGENT_WORK_DIR="/go" 56 | 57 | <%= setup_commands.join(" \n ") -%> 58 | # no arguments are passed so assume user wants to run the gocd server 59 | # we prepend "/go-agent/agent.sh" to the argument list 60 | if [[ $# -eq 0 ]] ; then 61 | set -- /go-agent/agent.sh "$@" 62 | fi 63 | 64 | # if running go server as root, then initialize directory structure and call ourselves as `go` user 65 | if [ "$1" = '/go-agent/agent.sh' ]; then 66 | 67 | if [ "$(id -u)" = '0' ]; then 68 | server_dirs=(config logs pipelines) 69 | 70 | yell "Creating directories and symlinks to hold GoCD configuration, data, and logs" 71 | 72 | # ensure working dir exist 73 | if [ ! -e "${AGENT_WORK_DIR}" ]; then 74 | try mkdir "${AGENT_WORK_DIR}" 75 | try chown go:go "${AGENT_WORK_DIR}" 76 | fi 77 | 78 | # ensure proper directory structure in the volume directory 79 | if [ ! -e "${VOLUME_DIR}" ]; then 80 | try mkdir "${VOLUME_DIR}" 81 | try chown go:go "${AGENT_WORK_DIR}" 82 | fi 83 | 84 | for each_dir in "${server_dirs[@]}"; do 85 | if [ ! -e "${VOLUME_DIR}/${each_dir}" ]; then 86 | try mkdir -v "${VOLUME_DIR}/${each_dir}" 87 | try chown go:go "${VOLUME_DIR}/${each_dir}" 88 | fi 89 | 90 | if [ ! -e "${AGENT_WORK_DIR}/${each_dir}" ]; then 91 | try ln -sv "${VOLUME_DIR}/${each_dir}" "${AGENT_WORK_DIR}/${each_dir}" 92 | try chown go:go "${AGENT_WORK_DIR}/${each_dir}" 93 | fi 94 | done 95 | 96 | if [ ! -e "${AGENT_WORK_DIR}/config/agent-bootstrapper-logback-include.xml" ]; then 97 | try cp -rfv "/go-agent/config/agent-bootstrapper-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-bootstrapper-logback-include.xml" 98 | try chown go:go "${VOLUME_DIR}/config/agent-bootstrapper-logback-include.xml" 99 | fi 100 | 101 | if [ ! -e "${AGENT_WORK_DIR}/config/agent-launcher-logback-include.xml" ]; then 102 | try cp -rfv "/go-agent/config/agent-launcher-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-launcher-logback-include.xml" 103 | try chown go:go "${VOLUME_DIR}/config/agent-launcher-logback-include.xml" 104 | fi 105 | 106 | if [ ! -e "${AGENT_WORK_DIR}/config/agent-logback-include.xml" ]; then 107 | try cp -rfv "/go-agent/config/agent-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-logback-include.xml" 108 | try chown go:go "${VOLUME_DIR}/config/agent-logback-include.xml" 109 | fi 110 | 111 | setup_autoregister_properties_file "${AGENT_WORK_DIR}/config/autoregister.properties" 112 | 113 | yell "Running custom scripts in /docker-entrypoint.d/ ..." 114 | 115 | # to prevent expansion to literal string `/docker-entrypoint.d/*` when there is nothing matching the glob 116 | shopt -s nullglob 117 | 118 | for file in /docker-entrypoint.d/*; do 119 | if [ -f "$file" ] && [ -x "$file" ]; then 120 | try "$file" 121 | else 122 | yell "Ignoring $file, it is either not a file or is not executable" 123 | fi 124 | done 125 | 126 | try exec /usr/local/sbin/tini -- /usr/local/sbin/gosu go "$0" "$@" 127 | fi 128 | fi 129 | 130 | # these 3 vars are used by `/go-agent/agent.sh`, so we export 131 | export AGENT_WORK_DIR 132 | export GO_AGENT_SYSTEM_PROPERTIES="${GO_AGENT_SYSTEM_PROPERTIES}${GO_AGENT_SYSTEM_PROPERTIES:+ }-Dgo.console.stdout=true" 133 | export AGENT_BOOTSTRAPPER_JVM_ARGS="${AGENT_BOOTSTRAPPER_JVM_ARGS}${AGENT_BOOTSTRAPPER_JVM_ARGS:+ }-Dgo.console.stdout=true" 134 | 135 | try exec "$@" 136 | --------------------------------------------------------------------------------