Skip to content

Commit 7124f46

Browse files
Merge pull request #11 from PythonGermany/standalone-docker-image
Standalone docker image setup
2 parents c9843a9 + b4982cd commit 7124f46

File tree

7 files changed

+93
-1
lines changed

7 files changed

+93
-1
lines changed

.dockerignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.clang-format
2+
.clangd
3+
4+
.git/
5+
.github/
6+
7+
.gitignore
8+
.gitmodules
9+
10+
.vscode/
11+
bin/
12+
cgi/
13+
docker/
14+
logs/
15+
obj/
16+
tests/
17+
18+
Dokerfile

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM alpine:latest AS build-stage
2+
3+
RUN apk add --no-cache make g++
4+
5+
COPY . /app
6+
7+
RUN make -C /app fclean custom ARG="-static -O3"
8+
9+
#FROM alpine:latest AS production-stage
10+
FROM alpine:latest AS production-stage
11+
12+
COPY --from=build-stage /app/bin/webserv /usr/bin/webserv
13+
COPY --from=build-stage /app/conf/webserv.conf /etc/webserv/
14+
COPY --from=build-stage /app/conf/mime.types /etc/webserv/
15+
COPY --from=build-stage /app/conf/sites-available/default.conf /etc/webserv/sites-available/
16+
17+
RUN mkdir /etc/webserv/sites-enabled
18+
RUN ln -s /etc/webserv/sites-available/default.conf /etc/webserv/sites-enabled/
19+
20+
RUN mkdir -p /var/www/html
21+
COPY --from=build-stage /app/websites/default/index.html /var/www/html/
22+
23+
EXPOSE 8080
24+
25+
CMD ["/usr/bin/webserv"]

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ custom:
111111
run: all
112112
$(BIN_DIR)/$(NAME) $(CONF_DIR)/$(CONF)
113113

114+
docker.build:
115+
docker build -t webserv .
116+
117+
docker.run:
118+
docker run --rm -p 8080:8080 --name webserv webserv:latest
119+
114120
lines:
115121
@wc -l $(SRC_DIR)/*.cpp $(INC_DIR)/*.hpp $(SRC_DIR)/*/*.cpp $(INC_DIR)/*/*.hpp | sort
116122

@@ -120,11 +126,12 @@ help:
120126
@echo " clean : Remove object files"
121127
@echo " fclean : Remove object files and the webserv binary"
122128
@echo " re : Rebuild the webserv binary (fclean + all)"
123-
@echo " cgi : Build the CGI program"
124129
@echo " performance : Build with optimization flags (-O3)"
125130
@echo " debug : Build with debugging symbols (-g)"
126131
@echo " custom : Build with custom CXXFLAGS (e.g., ARG='-DDEBUG')"
127132
@echo " run : Run webserv binary with project configuration file"
133+
@echo " docker.build : Build webserv docker image"
134+
@echo " docker.run : Run webserv docker image"
128135
@echo " lines : Count lines of code in source files"
129136

130137
.PHONY: all clean fclean re performance debug fsanitize custom flamegraph jmeter lines help

conf/sites-available/default.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
server {
2+
listen 0.0.0.0:8080;
3+
4+
root /var/www/html;
5+
6+
index index.html index.htm;
7+
}

include/poll/AConnection.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "Address.hpp"
1212
#include "CallbackPointer.hpp"
13+
#include "timeval.hpp"
1314

1415
// WEBSERV_CONFIG ----------- ACONNECTION VALUES -------------------
1516
/**

src/utils/utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "utils.hpp"
22

33
#include <algorithm>
4+
#include <climits>
45
#include <list>
56

67
std::string trim(const std::string& str, std::string chars) {

websites/default/index.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Welcome to webserv!</title>
6+
<style>
7+
html {
8+
color-scheme: light dark;
9+
}
10+
11+
body {
12+
width: 35em;
13+
margin: 0 auto;
14+
font-family: Tahoma, Verdana, Arial, sans-serif;
15+
}
16+
</style>
17+
</head>
18+
19+
<body>
20+
<h1>Welcome to webserv!</h1>
21+
<p>If you see this page, the webserv web server is successfully installed and
22+
working. Further configuration is required.</p>
23+
24+
<p>For online documentation and support please refer to
25+
<a href="https://github.com/PythonGermany/42_webserv?tab=readme-ov-file#introduction">github.com</a>.<br />
26+
Commercial support is not available at
27+
<a href="https://github.com/PythonGermany/42_webserv">github.com</a>.
28+
</p>
29+
30+
<p><em>Thank you for using webserv.</em></p>
31+
</body>
32+
33+
</html>

0 commit comments

Comments
 (0)