Skip to content
Draft
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
56 changes: 56 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Stage 1: Build the dynamic module
FROM nginx:1.24.0 AS builder

RUN apt-get update && apt-get install -y \
build-essential \
libpcre3-dev \
zlib1g-dev \
libssl-dev \
wget \
&& rm -rf /var/lib/apt/lists/*

# Download nginx source matching the base image version
RUN wget http://nginx.org/download/nginx-1.24.0.tar.gz \
&& tar -xzf nginx-1.24.0.tar.gz \
&& rm nginx-1.24.0.tar.gz

# Remove -Werror from nginx build system — it breaks C++ compilation
RUN sed -i 's/ -Werror//' /nginx-1.24.0/auto/cc/gcc

COPY . /morpheus/

# Download pugixml v1.15 source from the official repository.
# Runs after COPY so it works regardless of whether local pugixml/ files are present.
RUN mkdir -p /morpheus/pugixml \
&& wget -qO /morpheus/pugixml/pugixml.cpp https://raw.githubusercontent.com/zeux/pugixml/v1.15/src/pugixml.cpp \
&& wget -qO /morpheus/pugixml/pugixml.hpp https://raw.githubusercontent.com/zeux/pugixml/v1.15/src/pugixml.hpp \
&& wget -qO /morpheus/pugixml/pugiconfig.hpp https://raw.githubusercontent.com/zeux/pugixml/v1.15/src/pugiconfig.hpp

WORKDIR /nginx-1.24.0
RUN ./configure \
--with-ld-opt="-lstdc++" \
--with-cc-opt="-Wno-write-strings" \
--with-compat \
--add-dynamic-module=/morpheus \
&& make modules


# Stage 2: Production image
FROM nginx:1.24.0

# Copy the compiled module
COPY --from=builder /nginx-1.24.0/objs/ngx_http_morpheus_module.so /etc/nginx/modules/

# Copy nginx configuration and MIME types
COPY nginx_morpheus.conf /etc/nginx/nginx.conf
COPY mime.types /etc/nginx/mime.types

# nginx_morpheus.conf includes /usr/share/nginx/modules/*.conf which doesn't
# exist in the Docker image (unlike Ubuntu package installs); create it empty
RUN mkdir -p /usr/share/nginx/modules/

EXPOSE 80

# /dev/shm is a tmpfs mounted at container runtime, so its subdirectories
# cannot be created at build time — create them before starting nginx
CMD ["/bin/sh", "-c", "mkdir -p /dev/shm/nginx/client_temp && exec nginx -g 'daemon off;'"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ OBJS = $(SRCS:.cpp=.o)

all: morphdriver

morphdriver: $(OBJS) cxxopts.hpp
$(CC) $(CFLAGS) $(SRCS) -o $@
morphdriver: $(OBJS) pugixml.o cxxopts.hpp
$(CC) $(CFLAGS) $(OBJS) pugixml.o -o $@

clean:
rm -f *.o morphdriver
rm -f ngx_morpheus_internal.o morpheus_main.o morphdriver

2 changes: 2 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ ngx_addon_name=ngx_http_morpheus_module
MORPHEUS_SRCS=" \
$ngx_addon_dir/ngx_http_morpheus_module.cpp \
$ngx_addon_dir/ngx_morpheus_internal.cpp \
$ngx_addon_dir/pugixml/pugixml.cpp \
"

if test -n "$ngx_module_link"; then
ngx_module_type=HTTP
ngx_module_name=ngx_http_morpheus_module
ngx_module_incs="$ngx_addon_dir $ngx_addon_dir/pugixml"
ngx_module_srcs="$MORPHEUS_SRCS"
. auto/module
else
Expand Down
9 changes: 2 additions & 7 deletions morpheus_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ extern "C" {

using namespace std;

void morph_process(const char* encmpd, const char* drmconf, const char* iframesmpd, const bool alternativeconf);
void morph_process(const char* encmpd, const char* drmconf, const char* iframesmpd);

int main (int argc, char *argv[]) {

string inmpd_o, drmconf_o, iframesmpd_o;
bool alternativeconf_o = false;

try
{
Expand All @@ -22,7 +21,6 @@ int main (int argc, char *argv[]) {
("n", "encoder mpd file", cxxopts::value<string>())
("i", "iframes track mpd file", cxxopts::value<string>())
("d", "ckm encrypt context response xml file", cxxopts::value<string>())
("a", "alterantive insertion")
("h,help", "Print this help")
;

Expand All @@ -43,8 +41,6 @@ int main (int argc, char *argv[]) {
if (result.count("d"))
drmconf_o = result["d"].as<string>().c_str();

if (result.count("a"))
alternativeconf_o = true;
}
catch (const cxxopts::OptionException& e)
{
Expand All @@ -55,9 +51,8 @@ int main (int argc, char *argv[]) {
const char* inmpd = inmpd_o.length() ? inmpd_o.c_str() : NULL;
const char* drmconf = drmconf_o.length() ? drmconf_o.c_str() : NULL;
const char* iframesmpd = iframesmpd_o.length() ? iframesmpd_o.c_str() : NULL;
const bool alternativeconf = alternativeconf_o;

morph_process(inmpd, drmconf, iframesmpd, alternativeconf);
morph_process(inmpd, drmconf, iframesmpd);

return EXIT_SUCCESS;
}
Expand Down
18 changes: 3 additions & 15 deletions ngx_http_morpheus_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static char *ngx_http_morpheus_merge_loc_conf(ngx_conf_t *cf,
static ngx_int_t ngx_http_morpheus_init(ngx_conf_t *cf);

static char *ngx_http_morpheus(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
void morph_process(const char* encmpd, const char* drmconf, const char* iframesmpd, const bool alternativeconf);
void morph_process(const char* encmpd, const char* drmconf, const char* iframesmpd);

static ngx_conf_bitmask_t ngx_http_morpheus_methods_mask[] = {
{ ngx_string("off"), NGX_HTTP_DAV_OFF },
Expand Down Expand Up @@ -248,12 +248,11 @@ ngx_http_morpheus_put_handler(ngx_http_request_t *r)
{
size_t root;
time_t date;
ngx_str_t *temp, path, mode_value;
ngx_str_t *temp, path;
ngx_uint_t status;
ngx_file_info_t fi;
ngx_ext_rename_file_t ext;
ngx_http_morpheus_loc_conf_t *dlcf;
bool scte_to_alternative = false;

if (r->request_body == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Expand Down Expand Up @@ -290,18 +289,7 @@ ngx_http_morpheus_put_handler(ngx_http_request_t *r)

temp = &r->request_body->temp_file->file.name;

#define SCTE_TO_ALT_MODE "scte-to-alternative"
if (r->args.len > 0) {
if (ngx_http_arg(r, (u_char *) "mode", 4, &mode_value) == NGX_OK) {
if (mode_value.len == (sizeof(SCTE_TO_ALT_MODE) - 1) &&
ngx_strncmp(mode_value.data, SCTE_TO_ALT_MODE, sizeof(SCTE_TO_ALT_MODE) - 1) == 0)
{
scte_to_alternative = true;
}
}
}

morph_process((const char*)temp->data, NULL, NULL, scte_to_alternative);
morph_process((const char*)temp->data, NULL, NULL);

if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) {
status = NGX_HTTP_CREATED;
Expand Down
Loading