forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to use Stack logging in Docker
Backport of elastic#65778. Closes elastic#62758. Include the Stack log4j config in the Docker image, in order to make it possible to write logs in a container environment in the same way as for an archive or package deployment. This is useful in situations where the user is bind-mounting the logs directory and has their own arrangements for log shipping. To use stack logging, set the environment variable `ES_LOG_STYLE` to `file`. It can also be set to `console`, which is the same as not specifying it at all. The Docker logging config is now auto-generated at image build time, by running the default config through a transformer program when preparing the distribution in an image builder step. Also, in the docker distribution `build.gradle`, I changed a helper closure into a class with a static method in order to fix an issue where the Docker image was always being rebuilt, even when there were no changes.
- Loading branch information
1 parent
d82b892
commit 0906c33
Showing
12 changed files
with
424 additions
and
196 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
buildSrc/src/main/java/org/elasticsearch/gradle/docker/ShellRetry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.docker; | ||
|
||
/** | ||
* The methods in this class take a shell command and wrap it in retry logic, so that our | ||
* Docker builds can be more robust in the face of transient errors e.g. network issues. | ||
*/ | ||
public class ShellRetry { | ||
static String loop(String name, String command) { | ||
return loop(name, command, 4, "exit"); | ||
} | ||
|
||
static String loop(String name, String command, int indentSize, String exitKeyword) { | ||
String indent = " ".repeat(indentSize); | ||
|
||
StringBuilder commandWithRetry = new StringBuilder("for iter in {1..10}; do \n"); | ||
commandWithRetry.append(indent).append(" ").append(command).append(" && \n"); | ||
commandWithRetry.append(indent).append(" exit_code=0 && break || \n"); | ||
commandWithRetry.append(indent); | ||
commandWithRetry.append(" exit_code=$? && echo \"").append(name).append(" error: retry $iter in 10s\" && sleep 10; \n"); | ||
commandWithRetry.append(indent).append("done; \n"); | ||
commandWithRetry.append(indent).append(exitKeyword).append(" $exit_code"); | ||
|
||
// We need to escape all newlines so that the build process doesn't run all lines onto a single line | ||
return commandWithRetry.toString().replaceAll(" *\n", " \\\\\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 0 additions & 131 deletions
131
distribution/docker/src/docker/config/log4j2.properties
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.