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

Docker #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Docker #49

wants to merge 3 commits into from

Conversation

cboden
Copy link
Member

@cboden cboden commented Jan 31, 2023

Update packages to newer versions
Proxy based on URI path
Dockerize all website components
Fix cookie issues
@cboden cboden requested a review from mbonneau January 31, 2023 02:11
@WyriHaximus
Copy link
Contributor

@cboden Awesome! Will check it out locally and suggest some improvements, already spotted a few

Copy link
Contributor

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main questions:

  • Why 7.4? In theory, it should work on 8.1 and maybe 8.2
  • Couldn't get it to work locally
  • Why not go fully single container? (But that could be a second step.)

Comment on lines +1 to +20
FROM wyrihaximusnet/php:7.4-nts-alpine

RUN mkdir -p /opt/app/socketo.me
WORKDIR /opt/app/socketo.me

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php
RUN rm composer-setup.php
RUN chmod +x composer.phar

COPY bin bin
COPY src src
COPY composer.json ./
COPY composer.lock ./
RUN ./composer.phar install --ansi --no-interaction --prefer-dist -o --no-scripts --no-plugins
RUN rm composer.phar

ENTRYPOINT ["php"]
CMD ["bin/run-all-the-things.php"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would rewrite the Docker file to this mainly for size reasons: The original image is 434MB, using the slim image brings it down to 394MB. But installing the dependencies in a different stage and copying the entire thing over brings it down to 242MB.

Suggested change
FROM wyrihaximusnet/php:7.4-nts-alpine
RUN mkdir -p /opt/app/socketo.me
WORKDIR /opt/app/socketo.me
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php
RUN rm composer-setup.php
RUN chmod +x composer.phar
COPY bin bin
COPY src src
COPY composer.json ./
COPY composer.lock ./
RUN ./composer.phar install --ansi --no-interaction --prefer-dist -o --no-scripts --no-plugins
RUN rm composer.phar
ENTRYPOINT ["php"]
CMD ["bin/run-all-the-things.php"]
FROM wyrihaximusnet/php:7.4-nts-alpine-slim-dev AS install-dependencies
RUN mkdir -p /opt/app/socketo.me
WORKDIR /opt/app/socketo.me
COPY bin bin
COPY src src
COPY composer.* ./
RUN composer install --ansi --no-interaction --prefer-dist -o --no-scripts --no-plugins --no-dev
FROM wyrihaximusnet/php:7.4-nts-alpine-slim AS runtime
RUN mkdir -p /opt/app/socketo.me
WORKDIR /opt/app/socketo.me
COPY --from=install-dependencies /opt/app/socketo.me/ /opt/app/socketo.me/
ENTRYPOINT ["php"]
CMD ["bin/run-all-the-things.php"]

chat:
build:
context: ./
dockerfile: docker/Dockerfile-chat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dockerfile: docker/Dockerfile-chat
dockerfile: docker/Dockerfile-chat
target: runtime

@@ -158,4 +158,4 @@ ChatRoom = function(optDebug) {
);

return api;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

@@ -10,7 +10,9 @@
]
, "require": {
"php": ">=5.4.0"
, "cboden/Ratchet": "0.3.*"
, "cboden/ratchet": "^0.4"
, "react/event-loop": "^1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, "react/event-loop": "^1.0"
, "react/event-loop": "^1.3"

Comment on lines +42 to +54
Loop::addSignal(SIGINT, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;

Loop::removeSignal(SIGINT, $func);
Loop::get()->stop();
});
Loop::addSignal(SIGTERM, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;

Loop::removeSignal(SIGTERM, $func);
Loop::get()->stop();
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either

Suggested change
Loop::addSignal(SIGINT, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;
Loop::removeSignal(SIGINT, $func);
Loop::get()->stop();
});
Loop::addSignal(SIGTERM, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;
Loop::removeSignal(SIGTERM, $func);
Loop::get()->stop();
});
Loop::addSignal(SIGINT, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;
Loop::get()->stop();
});
Loop::addSignal(SIGTERM, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;
Loop::get()->stop();
});

or

Suggested change
Loop::addSignal(SIGINT, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;
Loop::removeSignal(SIGINT, $func);
Loop::get()->stop();
});
Loop::addSignal(SIGTERM, $func = function ($signal) use (&$func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;
Loop::removeSignal(SIGTERM, $func);
Loop::get()->stop();
});
$func = function ($signal) use ($func) {
echo 'Received signal: ', (string)$signal, PHP_EOL;
Loop::removeSignal(SIGINT, $func);
Loop::removeSignal(SIGTERM, $func);
Loop::get()->stop();
};
Loop::addSignal(SIGINT, $func);
Loop::addSignal(SIGTERM, $func);

But probably also a stop function, if it doesn't exists on Ratchet, would help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants