Skip to content

Commit

Permalink
Rename packages to wazuh-indexer (#69)
Browse files Browse the repository at this point in the history
* Rename packages to wazuh-indexer

* Include VERSION file into packages

* Apply Wazuh version to packages names

* Improve build.sh script

Apply suggestions from ShellCheck
  • Loading branch information
AlexRuiz7 committed Jan 4, 2024
1 parent 02faad5 commit cf57f72
Show file tree
Hide file tree
Showing 28 changed files with 280 additions and 265 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.9.0
4.9.0
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void configureGeneralTaskDefaults(Project project) {
project.getTasks().withType(AbstractArchiveTask.class).configureEach(t -> {
String subdir = archiveTaskToSubprojectName(t.getName());
t.getDestinationDirectory().set(project.file(subdir + "/build/distributions"));
t.getArchiveBaseName().set("opensearch-min");
t.getArchiveBaseName().set("wazuh-indexer-min");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void registerBwcArtifacts(Project bwcProject, DistributionProject distri
String expandedDistConfiguration = "expanded-" + projectName;
bwcProject.getConfigurations().create(expandedDistConfiguration);
bwcProject.getArtifacts().add(expandedDistConfiguration, distributionProject.getExpandedDistDirectory(), artifact -> {
artifact.setName("opensearch");
artifact.setName("wazuh-indexer");
artifact.builtBy(buildBwcTask);
artifact.setType("directory");
});
Expand All @@ -132,7 +132,7 @@ private void registerBwcArtifacts(Project bwcProject, DistributionProject distri

private void registerDistributionArchiveArtifact(Project bwcProject, DistributionProject distributionProject, String buildBwcTask) {
String artifactFileName = distributionProject.getDistFile().getName();
String artifactName = "opensearch";
String artifactName = "wazuh-indexer";

String suffix = artifactFileName.endsWith("tar.gz") ? "tar.gz" : artifactFileName.substring(artifactFileName.length() - 3);
int archIndex = artifactFileName.indexOf("x64");
Expand Down Expand Up @@ -248,12 +248,12 @@ private static class DistributionProject {
if (version.onOrAfter("1.1.0")) {
this.distFile = new File(
checkoutDir,
baseDir + "/" + name + "/build/distributions/opensearch-min-" + version + "-SNAPSHOT" + classifier + "." + extension
baseDir + "/" + name + "/build/distributions/wazuh-indexer-min-" + version + "-SNAPSHOT" + classifier + "." + extension
);
} else {
this.distFile = new File(
checkoutDir,
baseDir + "/" + name + "/build/distributions/opensearch-" + version + "-SNAPSHOT" + classifier + "." + extension
baseDir + "/" + name + "/build/distributions/wazuh-indexer-" + version + "-SNAPSHOT" + classifier + "." + extension
);
}
// we only ported this down to the 7.x branch.
Expand Down
6 changes: 5 additions & 1 deletion distribution/archives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import org.opensearch.gradle.JavaPackageType
apply plugin: 'opensearch.internal-distribution-archive-setup'

CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String platform, String architecture, JavaPackageType java) {
version = rootProject.file('VERSION').getText()
return copySpec {
into("opensearch-${version}") {
into("wazuh-indexer-${version}") {
into('lib') {
with libFiles()
}
Expand Down Expand Up @@ -71,6 +72,9 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla
pluginsDir.getParent()
}
}
into('') {
with versionFile()
}
from(rootProject.projectDir) {
include 'README.md'
}
Expand Down
39 changes: 23 additions & 16 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
}

versionFile = {
copySpec {
from(rootProject.file('VERSION'))
fileMode 0644
}
}

modulesFiles = { platform ->
copySpec {
eachFile {
Expand Down Expand Up @@ -523,27 +530,27 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
* <dt>path.conf</dt>
* <dd>The default directory from which to load configuration. This is used in
* the packaging scripts, but in that context it is always
* /etc/opensearch. Its also used in bin/opensearch-plugin, where it is
* /etc/opensearch for the os packages but $OPENSEARCH_HOME/config otherwise.</dd>
* /etc/wazuh-indexer. Its also used in bin/opensearch-plugin, where it is
* /etc/wazuh-indexer for the os packages but $OPENSEARCH_HOME/config otherwise.</dd>
* <dt>path.env</dt>
* <dd>The env file sourced before bin/opensearch to set environment
* variables. Think /etc/defaults/opensearch.</dd>
* variables. Think /etc/defaults/wazuh-indexer.</dd>
* <dt>heap.min and heap.max</dt>
* <dd>Default min and max heap</dd>
* <dt>scripts.footer</dt>
* <dd>Footer appended to control scripts embedded in the distribution that is
* (almost) entirely there for cosmetic reasons.</dd>
* <dt>stopping.timeout</dt>
* <dd>RPM's init script needs to wait for opensearch to stop before
* <dd>RPM's init script needs to wait for wazuh-indexer to stop before
* returning from stop and it needs a maximum time to wait. This is it. One
* day. DEB retries forever.</dd>
* </dl>
*/
subprojects {
ext.expansionsForDistribution = { distributionType, jdk ->
final String defaultHeapSize = "1g"
final String packagingPathData = "path.data: /var/lib/opensearch"
final String pathLogs = "/var/log/opensearch"
final String packagingPathData = "path.data: /var/lib/wazuh-indexer"
final String pathLogs = "/var/log/wazuh-indexer"
final String packagingPathLogs = "path.logs: ${pathLogs}"
final String packagingLoggc = "${pathLogs}/gc.log"

Expand All @@ -558,8 +565,8 @@ subprojects {
'project.version': version,

'path.conf': [
'deb': '/etc/opensearch',
'rpm': '/etc/opensearch',
'deb': '/etc/wazuh-indexer',
'rpm': '/etc/wazuh-indexer',
'def': '"$OPENSEARCH_HOME"/config'
],
'path.data': [
Expand All @@ -568,15 +575,15 @@ subprojects {
'def': '#path.data: /path/to/data'
],
'path.env': [
'deb': '/etc/default/opensearch',
'rpm': '/etc/sysconfig/opensearch',
'deb': '/etc/default/wazuh-indexer',
'rpm': '/etc/sysconfig/wazuh-indexer',
/* There isn't one of these files for tar or zip but its important to
make an empty string here so the script can properly skip it. */
'def': 'if [ -z "$OPENSEARCH_PATH_CONF" ]; then OPENSEARCH_PATH_CONF="$OPENSEARCH_HOME"/config; done',
],
'source.path.env': [
'deb': 'source /etc/default/opensearch',
'rpm': 'source /etc/sysconfig/opensearch',
'deb': 'source /etc/default/wazuh-indexer',
'rpm': 'source /etc/sysconfig/wazuh-indexer',
'def': 'if [ -z "$OPENSEARCH_PATH_CONF" ]; then OPENSEARCH_PATH_CONF="$OPENSEARCH_HOME"/config; fi',
],
'path.logs': [
Expand All @@ -594,14 +601,14 @@ subprojects {
'heap.max': defaultHeapSize,

'heap.dump.path': [
'deb': "-XX:HeapDumpPath=/var/lib/opensearch",
'rpm': "-XX:HeapDumpPath=/var/lib/opensearch",
'deb': "-XX:HeapDumpPath=/var/lib/wazuh-indexer",
'rpm': "-XX:HeapDumpPath=/var/lib/wazuh-indexer",
'def': "-XX:HeapDumpPath=data"
],

'error.file': [
'deb': "-XX:ErrorFile=/var/log/opensearch/hs_err_pid%p.log",
'rpm': "-XX:ErrorFile=/var/log/opensearch/hs_err_pid%p.log",
'deb': "-XX:ErrorFile=/usr/share/wazuh-indexer/hs_err_pid%p.log",
'rpm': "-XX:ErrorFile=/usr/share/wazuh-indexer/hs_err_pid%p.log",
'def': "-XX:ErrorFile=logs/hs_err_pid%p.log"
],

Expand Down
2 changes: 1 addition & 1 deletion distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ext.expansions = { Architecture architecture, DockerBase base, boolean local ->
classifier = "linux-\$(arch)"
}

final String opensearch = "opensearch-min-${VersionProperties.getOpenSearch()}-${classifier}.tar.gz"
final String opensearch = "wazuh-indexer-min-${VersionProperties.getOpenSearch()}-${classifier}.tar.gz"

/* Both the following Dockerfile commands put the resulting artifact at
* the same location, regardless of classifier, so that the commands that
Expand Down
4 changes: 2 additions & 2 deletions distribution/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
- node.store.allow_mmap=false
volumes:
- ./build/repo:/tmp/opensearch-repo
- ./build/logs/1:/usr/share/opensearch/logs
- ./build/logs/1:/usr/share/wazuh-indexer/logs
ports:
- "9200"
ulimits:
Expand All @@ -42,7 +42,7 @@ services:
- node.store.allow_mmap=false
volumes:
- ./build/repo:/tmp/opensearch-repo
- ./build/logs/2:/usr/share/opensearch/logs
- ./build/logs/2:/usr/share/wazuh-indexer/logs
ports:
- "9200"
ulimits:
Expand Down
4 changes: 2 additions & 2 deletions distribution/docker/docker-test-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e -o pipefail

cd /usr/share/opensearch/bin/
cd /usr/share/wazuh-indexer/bin/

/usr/local/bin/docker-entrypoint.sh | tee > /usr/share/opensearch/logs/console.log
/usr/local/bin/docker-entrypoint.sh | tee > /usr/share/wazuh-indexer/logs/console.log
24 changes: 12 additions & 12 deletions distribution/docker/src/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ RUN set -eux ; \\
mv \${tini_bin} /tini ; \\
chmod +x /tini
RUN mkdir /usr/share/opensearch
WORKDIR /usr/share/opensearch
RUN mkdir /usr/share/wazuh-indexer
WORKDIR /usr/share/wazuh-indexer
${source_opensearch}
RUN tar zxf /opt/opensearch.tar.gz --strip-components=1
RUN sed -i -e 's/OPENSEARCH_DISTRIBUTION_TYPE=tar/OPENSEARCH_DISTRIBUTION_TYPE=docker/' /usr/share/opensearch/bin/opensearch-env
RUN sed -i -e 's/OPENSEARCH_DISTRIBUTION_TYPE=tar/OPENSEARCH_DISTRIBUTION_TYPE=docker/' /usr/share/wazuh-indexer/bin/opensearch-env
RUN mkdir -p config config/jvm.options.d data logs
RUN chmod 0775 config config/jvm.options.d data logs
COPY config/opensearch.yml config/log4j2.properties config/
Expand Down Expand Up @@ -74,27 +74,27 @@ RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-* && \\
done; \\
(exit \$exit_code)
RUN groupadd -g 1000 opensearch && \\
adduser -u 1000 -g 1000 -G 0 -d /usr/share/opensearch opensearch && \\
chmod 0775 /usr/share/opensearch && \\
chown -R 1000:0 /usr/share/opensearch
RUN groupadd -g 1000 wazuh-indexer && \\
adduser -u 1000 -g 1000 -G 0 -d /usr/share/wazuh-indexer wazuh-indexer && \\
chmod 0775 /usr/share/wazuh-indexer && \\
chown -R 1000:0 /usr/share/wazuh-indexer
WORKDIR /usr/share/opensearch
COPY --from=builder --chown=1000:0 /usr/share/opensearch /usr/share/opensearch
WORKDIR /usr/share/wazuh-indexer
COPY --from=builder --chown=1000:0 /usr/share/wazuh-indexer /usr/share/wazuh-indexer
COPY --from=builder --chown=0:0 /tini /tini
# Replace OpenJDK's built-in CA certificate keystore with the one from the OS
# vendor. The latter is superior in several ways.
# REF: https://github.com/elastic/elasticsearch-docker/issues/171
RUN ln -sf /etc/pki/ca-trust/extracted/java/cacerts /usr/share/opensearch/jdk/lib/security/cacerts
RUN ln -sf /etc/pki/ca-trust/extracted/java/cacerts /usr/share/wazuh-indexer/jdk/lib/security/cacerts

ENV PATH /usr/share/opensearch/bin:\$PATH
ENV PATH /usr/share/wazuh-indexer/bin:\$PATH

COPY bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh

# The JDK's directories' permissions don't allow `java` to be executed under a different
# group to the default. Fix this.
RUN find /usr/share/opensearch/jdk -type d -exec chmod 0755 '{}' \\; && \\
RUN find /usr/share/wazuh-indexer/jdk -type d -exec chmod 0755 '{}' \\; && \\
chmod g=u /etc/passwd && \\
chmod 0775 /usr/local/bin/docker-entrypoint.sh

Expand Down
8 changes: 4 additions & 4 deletions distribution/docker/src/docker/bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fi
# This is also sourced in opensearch-env, and is only needed here
# as well because we use ELASTIC_PASSWORD below. Sourcing this script
# is idempotent.
source /usr/share/opensearch/bin/opensearch-env-from-file
source /usr/share/wazuh-indexer/bin/opensearch-env-from-file

if [[ -f bin/opensearch-users ]]; then
# Check for the ELASTIC_PASSWORD environment variable to set the
Expand All @@ -56,7 +56,7 @@ if [[ -f bin/opensearch-users ]]; then
# enabled, but we have no way of knowing which node we are yet. We'll just
# honor the variable if it's present.
if [[ -n "$ELASTIC_PASSWORD" ]]; then
[[ -f /usr/share/opensearch/config/opensearch.keystore ]] || (run_as_other_user_if_needed opensearch-keystore create)
[[ -f /usr/share/wazuh-indexer/config/opensearch.keystore ]] || (run_as_other_user_if_needed opensearch-keystore create)
if ! (run_as_other_user_if_needed opensearch-keystore has-passwd --silent) ; then
# keystore is unencrypted
if ! (run_as_other_user_if_needed opensearch-keystore list | grep -q '^bootstrap.password$'); then
Expand All @@ -76,8 +76,8 @@ fi
if [[ "$(id -u)" == "0" ]]; then
# If requested and running as root, mutate the ownership of bind-mounts
if [[ -n "$TAKE_FILE_OWNERSHIP" ]]; then
chown -R 1000:0 /usr/share/opensearch/{data,logs}
chown -R 1000:0 /usr/share/wazuh-indexer/{data,logs}
fi
fi

run_as_other_user_if_needed /usr/share/opensearch/bin/opensearch <<<"$KEYSTORE_PASSWORD"
run_as_other_user_if_needed /usr/share/wazuh-indexer/bin/opensearch <<<"$KEYSTORE_PASSWORD"
Loading

0 comments on commit cf57f72

Please sign in to comment.