Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make latestVersion.js update without restart #1638

Merged
merged 6 commits into from May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
@@ -0,0 +1,2 @@
target/
!target/*.war
93 changes: 4 additions & 89 deletions Dockerfile 100755 → 100644
@@ -1,92 +1,7 @@
# Created by laura_cowen@uk.ibm.com, Twitter/GitHub/Docker username: @lauracowen
# 2017-11-02
# Updated Oct. 2018 by Kin Ueng
# Installing and running Jekyll based on: based on https://blog.codeship.com/a-beginners-guide-to-the-dockerfile/
# NodeJS and NPM sections based on: https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a
FROM open-liberty:kernel

# The purpose of this dockerfile is to run your Jekyll website so you don't have to install Jekyll
# and all of Jekyll's pre-requisite software.
# You can view the site in a browser on your local (host) machine (at http://0.0.0.0:4000).
# You can then modify website source files on your local (host) machine.
# When you save a changed file, the changes are automatically rebuilt by Jekyll in the container and you can almost immediately
# see the changes when you refresh your browser.

# To build this image, from the directory that contains this Dockerfile:
# docker build --tag lauracowen/jekyll .
#
# To run a container:
# docker run --name jekyll -it -d -p 4000:4000 -v <root directory of Jekyll site on host machine>:/home/jekyll lauracowen/jekyll

# Use the official Ruby image as a parent image
FROM ruby:latest

# INSTALL NODEJS AND NPM (it's a dependency of something in the Jekyll setup)

# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# update the repository sources list
# and install dependencies
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get -y autoclean

# nvm environment variables
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 9.0.0

# install nvm
# https://github.com/creationix/nvm#install-script
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash

# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

# confirm installation
RUN node -v
RUN npm -v

# INSTALLING AND RUNNING JEKYLL

# create a user and group for Jekyll, set appropriate permissions, install the Jekyll gem
RUN mkdir -p /home/jekyll \
&& groupadd -rg 1000 jekyll \
&& useradd -rg jekyll -u 1000 -d /home/jekyll jekyll \
&& chown jekyll:jekyll /home/jekyll

# Create a mount point where Docker can access the source files on my local system (host system)
VOLUME /home/jekyll

# Set the working directory
WORKDIR /home/jekyll

# openliberty.io gem dependencies
COPY ./scripts /home/jekyll/scripts
RUN scripts/build_gem_dependencies.sh

# openliberty.io custom gems
COPY ./gems /home/jekyll/gems
RUN pushd gems/ol-asciidoc \
&& gem build ol-asciidoc.gemspec \
&& gem install ol-asciidoc-0.0.1.gem \
&& popd

RUN pushd gems/ol-target-blank \
&& gem build ol-target-blank.gemspec \
&& gem install ol-target-blank-0.0.1.gem \
&& popd

# Serve the site
ENTRYPOINT ["bash", "./scripts/jekyll_serve_dev.sh"]

# Make port 4000 available to the world outside this container
EXPOSE 4000
ENV SEC_TLS_TRUSTDEFAULTCERTS true

COPY src/main/wlp/server.xml /config/server.xml

COPY target/openliberty.war /config/dropins/openliberty.war
92 changes: 92 additions & 0 deletions Dockerfile-blogs
@@ -0,0 +1,92 @@
# Created by laura_cowen@uk.ibm.com, Twitter/GitHub/Docker username: @lauracowen
# 2017-11-02
# Updated Oct. 2018 by Kin Ueng
# Installing and running Jekyll based on: based on https://blog.codeship.com/a-beginners-guide-to-the-dockerfile/
# NodeJS and NPM sections based on: https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a

# The purpose of this dockerfile is to run your Jekyll website so you don't have to install Jekyll
# and all of Jekyll's pre-requisite software.
# You can view the site in a browser on your local (host) machine (at http://0.0.0.0:4000).
# You can then modify website source files on your local (host) machine.
# When you save a changed file, the changes are automatically rebuilt by Jekyll in the container and you can almost immediately
# see the changes when you refresh your browser.

# To build this image, from the directory that contains this Dockerfile:
# docker build --tag lauracowen/jekyll .
#
# To run a container:
# docker run --name jekyll -it -d -p 4000:4000 -v <root directory of Jekyll site on host machine>:/home/jekyll lauracowen/jekyll

# Use the official Ruby image as a parent image
FROM ruby:latest

# INSTALL NODEJS AND NPM (it's a dependency of something in the Jekyll setup)

# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# update the repository sources list
# and install dependencies
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get -y autoclean

# nvm environment variables
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 9.0.0

# install nvm
# https://github.com/creationix/nvm#install-script
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash

# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

# confirm installation
RUN node -v
RUN npm -v

# INSTALLING AND RUNNING JEKYLL

# create a user and group for Jekyll, set appropriate permissions, install the Jekyll gem
RUN mkdir -p /home/jekyll \
&& groupadd -rg 1000 jekyll \
&& useradd -rg jekyll -u 1000 -d /home/jekyll jekyll \
&& chown jekyll:jekyll /home/jekyll

# Create a mount point where Docker can access the source files on my local system (host system)
VOLUME /home/jekyll

# Set the working directory
WORKDIR /home/jekyll

# openliberty.io gem dependencies
COPY ./scripts /home/jekyll/scripts
RUN scripts/build_gem_dependencies.sh

# openliberty.io custom gems
COPY ./gems /home/jekyll/gems
RUN pushd gems/ol-asciidoc \
&& gem build ol-asciidoc.gemspec \
&& gem install ol-asciidoc-0.0.1.gem \
&& popd

RUN pushd gems/ol-target-blank \
&& gem build ol-target-blank.gemspec \
&& gem install ol-target-blank-0.0.1.gem \
&& popd

# Serve the site
ENTRYPOINT ["bash", "./scripts/jekyll_serve_dev.sh"]

# Make port 4000 available to the world outside this container
EXPOSE 4000


62 changes: 56 additions & 6 deletions pom.xml
Expand Up @@ -29,13 +29,22 @@
<type>pom</type>
<scope>provided</scope>
</dependency>
<!-- BEGIN: Needed to compile and run unit tests -->
<!-- Junit 5 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<!-- MicroShed Testing-->
<dependency>
<groupId>org.microshed</groupId>
<artifactId>microshed-testing-liberty</artifactId>
<version>0.9</version>
<scope>test</scope>
</dependency>

<!-- CXF REST client for integration tests-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-mp-client</artifactId>
Expand All @@ -49,14 +58,35 @@
<scope>test</scope>
</dependency>

<!-- JSON-B implementation for tests -->
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>1.0.6</version>
<scope>test</scope>
</dependency>

<!-- END: Needed to compile and run unit tests -->
<!-- Enable Logging for MicroShed Testing-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
<scope>test</scope>
</dependency>

<!-- Mock server for mock DHE server support -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mockserver</artifactId>
<version>1.14.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.5.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -79,7 +109,15 @@
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.2</version>
<version>3.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand All @@ -94,6 +132,18 @@
</bootstrapProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4 changes: 2 additions & 2 deletions src/main/java/io/openliberty/website/BuildsManager.java
Expand Up @@ -50,11 +50,11 @@ public BuildData getData() {
}

public Map<BuildType, Set<BuildInfo>> getBuilds() {
return dheBuilds.getBuildData().builds;
return dheBuilds.getBuildData().getBuilds();
}

public LatestReleases getLatestReleases() {
return dheBuilds.getBuildData().latestReleases;
return dheBuilds.getBuildData().getLatestReleases();
}

public LastUpdate getStatus() {
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/io/openliberty/website/LatestVersion.java
Expand Up @@ -11,13 +11,17 @@
package io.openliberty.website;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.openliberty.website.data.LatestReleases;
import io.openliberty.website.data.BuildInfo;
import io.openliberty.website.events.RuntimeRelease;

/**
* The Open Liberty landing page makes a request to a latestVersion.js file in order
Expand All @@ -33,35 +37,38 @@ public class LatestVersion extends HttpServlet {
@Inject
private BuildsManager manager;

private String response;
private String version = "0.0.0.0";
private String template = "var latestReleasedVersion = {\r\n" +
" version: '0.0.0.0',\r\n" +
" productName : 'Open Liberty',\r\n" +
" availableFrom : 'https://openliberty.io/downloads?welcome'\r\n" +
"};";

private static AtomicReference<String> response = new AtomicReference<>();

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// send the response.
resp.setContentType("application/javascript");
resp.getWriter().println(response);
resp.getWriter().println(response.get());
}

/**
* This method gets the latest release and updates the template replacing the Liberty
* version with the most recent version.
*
* Note this was written assuming that doing it in init would be more efficient, however
* either each request results in a new servlet instance making this redundant, or there
* is reuse at which point the data will be stale when the whole point of this is to be
* super current. This note is here because this needs looking at again.
*/
public void init() {
LatestReleases releases = manager.getLatestReleases();
String v = releases.runtime.version;
if (!v.equals(version)) {
response = template.replaceAll("0\\.0\\.0\\.0", v);
version = v;
}
releaseUpdate(manager.getLatestReleases().runtime);
}

/**
* This method will update the response value when it is notified of a change
* to the runtime release.
*
* @param releaseInfo the build info of the supplied release build
*/
public void releaseUpdate(@Observes @RuntimeRelease BuildInfo releaseInfo) {
String newValue = template.replaceAll("0\\.0\\.0\\.0", releaseInfo.version);

response.set(newValue);
}
}
}
Expand Up @@ -26,7 +26,7 @@
* This is the main JAX-RS entry point for the Open Liberty website REST API.
* The API is defined in the source repo website-api.yml.
*/
@ApplicationPath("api")
@ApplicationPath("/api")
@Path("/")
@RequestScoped
public class OpenLibertyEndpoint extends Application {
Expand Down