Skip to content

Commit

Permalink
Merge pull request fabric8-updatebot#6 from jstrachan/malarkey
Browse files Browse the repository at this point in the history
added docker support
  • Loading branch information
jstrachan authored Jan 30, 2018
2 parents e7835e4 + 7b0b613 commit bfcb3de
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 10 deletions.
1 change: 1 addition & 0 deletions jx/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jenkins X Shell scripts for CI / CD
14 changes: 6 additions & 8 deletions jx/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ git checkout master
# until we switch to the new kubernetes / jenkins credential implementation use git credentials store
git config credential.helper store

# so we can retrieve the version in later steps
echo $(jx-release-version) > target/VERSION
mvn versions:set -DnewVersion=$(cat target/VERSION)
export VERSION="$(jx-release-version)"
echo "Setting the maven version to ${VERSION}"

mvn versions:set -DnewVersion=${VERSION}

mvn clean -B
mvn -V -B -e -U install org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7:deploy -P release -P openshift -DnexusUrl=https://oss.sonatype.org -DserverId=oss-sonatype-staging

# now the sonatype repo ids will be on disk

#jx step nexus_release

#git commit -a -m 'release $(cat target/VERSION)'
#git push origin release-$(cat target/VERSION)

#jx step nexus release
#jx step tag --version ${VERSION}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.jenkins.updatebot.kind;

import io.jenkins.updatebot.kind.brew.BrewUpdater;
import io.jenkins.updatebot.kind.docker.DockerUpdater;
import io.jenkins.updatebot.kind.file.FileUpdater;
import io.jenkins.updatebot.kind.helm.HelmUpdater;
import io.jenkins.updatebot.kind.maven.MavenUpdater;
Expand All @@ -30,7 +31,8 @@ public enum Kind {
MAVEN("maven", new MavenUpdater()),
NPM("npm", new PackageJsonUpdater()),
PLUGINS("plugins", new PluginsUpdater()),
BREW("brew", new BrewUpdater());
BREW("brew", new BrewUpdater()),
DOCKER("docker", new DockerUpdater());

private String name;
private Updater updater;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Red Hat, Inc.
* Copyright 2018 Original Authors
*
* Red Hat licenses this file to you under the Apache License, version
* 2.0 (the "License"); you may not use this file except in compliance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright 2018 Original Authors
*
* Red Hat 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 io.jenkins.updatebot.kind.docker;

import io.fabric8.utils.Files;
import io.fabric8.utils.IOHelpers;
import io.jenkins.updatebot.commands.CommandContext;
import io.jenkins.updatebot.commands.PushVersionChangesContext;
import io.jenkins.updatebot.kind.UpdaterSupport;
import io.jenkins.updatebot.model.Dependencies;
import io.jenkins.updatebot.model.DependencyVersionChange;
import io.jenkins.updatebot.support.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
*/
public class DockerUpdater extends UpdaterSupport {
private static final transient Logger LOG = LoggerFactory.getLogger(DockerUpdater.class);

@Override
public boolean isApplicable(CommandContext context) {
return FileHelper.isFile(context.file("Dockerfile"));
}

@Override
public void addVersionChangesFromSource(CommandContext context, Dependencies dependencyConfig, List<DependencyVersionChange> list) throws IOException {
}

@Override
public boolean pushVersions(CommandContext parentContext, List<DependencyVersionChange> changes) throws IOException {
boolean answer = false;
if (isApplicable(parentContext)) {
for (DependencyVersionChange step : changes) {
PushVersionChangesContext context = new PushVersionChangesContext(parentContext, step);
boolean updated = pushVersions(context);
if (updated) {
answer = true;
} else {
parentContext.removeChild(context);
}
}
}
return answer;
}

protected boolean pushVersions(PushVersionChangesContext context) throws IOException {
boolean answer = false;
List<PushVersionChangesContext.Change> changes = context.getChanges();
for (PushVersionChangesContext.Change change : changes) {
if (doPushVersionChange(context, context.getName(), context.getValue())) {
answer = true;
}
}
DependencyVersionChange step = context.getStep();
if (step != null) {
if (doPushVersionChange(context, step.getDependency(), context.getValue())) {
answer = true;
}
}
return answer;
}


private boolean doPushVersionChange(PushVersionChangesContext context, String name, String value) throws IOException {
boolean answer = false;
File dir = context.getDir();
if (Files.isDirectory(dir)) {
File[] files = dir.listFiles();
if (files != null) {
for (File file : files) {
String fileName = file.getName();
if (Files.isFile(file) && fileName.equals("Dockerfile") || fileName.startsWith("Dockerfile.")) {
if (updateDockerfile(context, file, name, value)) {
answer = true;
}
}
}
}
}
return answer;
}

private boolean updateDockerfile(PushVersionChangesContext context, File file, String name, String value) throws IOException {
String[] linePrefixes = {
"FROM " + name + ":",
"ENV " + name + " "
};
List<String> lines = IOHelpers.readLines(file);
boolean answer = false;
for (int i = 0, size = lines.size(); i < size; i++) {
String line = lines.get(i);
for (String linePrefix : linePrefixes) {
if (line.startsWith(linePrefix)) {
String remaining = line.substring(linePrefix.length());
if (!remaining.trim().equals(value)) {
answer = true;
lines.set(i, linePrefix + value);
}
}
}
}
if (answer) {
IOHelpers.writeLines(file, lines);
}
return answer;
}
}

0 comments on commit bfcb3de

Please sign in to comment.