diff --git a/examples/RandomImageWebApp.java b/examples/RandomImageWebApp.java new file mode 100644 index 00000000..be7a2cdd --- /dev/null +++ b/examples/RandomImageWebApp.java @@ -0,0 +1,51 @@ +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.DefaultServlet; +import org.eclipse.jetty.servlet.ServletContextHandler; +import javax.servlet.http.*; +import javax.servlet.ServletException; +import java.io.*; +import java.util.Random; + +public class RandomImageWebApp extends HttpServlet { + private String[] imagePaths = { + "images/image1.jpg", + "images/image2.jpg", + "images/image3.jpg" + }; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + Random rand = new Random(); + int index = rand.nextInt(imagePaths.length); + File file = new File(imagePaths[index]); + + resp.setContentType("image/jpeg"); + resp.setHeader("Content-Disposition", "inline"); + + try (OutputStream out = resp.getOutputStream(); + FileInputStream in = new FileInputStream(file)) { + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + } + } + } + + public static void main(String[] args) throws Exception { + Server server = new Server(8000); + + ServletContextHandler handler = new ServletContextHandler(); + handler.setContextPath("/"); + + handler.addServlet(RandomImageWebApp.class, "/image"); + handler.addServlet(DefaultServlet.class, "/"); + + handler.setResourceBase("."); + + server.setHandler(handler); + server.start(); + server.join(); + } +} diff --git a/examples/golang-multi-stage-docker-build/Dockerfile b/examples/golang-multi-stage-docker-build/Dockerfile index 846388a0..ac75c5d5 100644 --- a/examples/golang-multi-stage-docker-build/Dockerfile +++ b/examples/golang-multi-stage-docker-build/Dockerfile @@ -16,7 +16,9 @@ RUN CGO_ENABLED=0 go build -o /app . # HERE STARTS THE MAGIC OF MULTI STAGE BUILD ############################################ -FROM scratch + +FROM openjdk:11-jre-slim +COPY --from=build /app /app # Copy the compiled binary from the build stage COPY --from=build /app /app diff --git a/examples/python-web-app/Dockerfile b/examples/python-web-app/Dockerfile index 5e158392..6f4819df 100644 --- a/examples/python-web-app/Dockerfile +++ b/examples/python-web-app/Dockerfile @@ -6,9 +6,10 @@ COPY requirements.txt /app COPY devops /app RUN apt-get update && \ - apt-get install -y python3 python3-pip && \ - pip install -r requirements.txt && \ - cd devops + apt-get install -y python3 python3-pip python3-venv && \ + python3 -m venv /app/venv && \ + . /app/venv/bin/activate && \ + pip install -r requirements.txt ENTRYPOINT ["python3"] CMD ["manage.py", "runserver", "0.0.0.0:8000"]