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

Rahmanansii patch 1 #92

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions examples/RandomImageWebApp.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 3 additions & 1 deletion examples/golang-multi-stage-docker-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions examples/python-web-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down