Adding initial Docker support.
This commit is contained in:
parent
2a3d66642e
commit
708618f6d1
@ -5,6 +5,11 @@ document will guide in the process of
|
||||
deploying a development version of
|
||||
this project.
|
||||
|
||||
## Docker
|
||||
|
||||
Docker is the recommended way for novices to
|
||||
test this software, to use it... (In progress)
|
||||
|
||||
## Installing
|
||||
|
||||
This guide is centered on Debian 12, if
|
||||
|
10
Dockerfile.template
Normal file
10
Dockerfile.template
Normal file
@ -0,0 +1,10 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
RUN apt update
|
||||
RUN apt install -y git pwgen liblocal-lib-perl libpq-dev nodejs sassc npm
|
||||
RUN useradd -m las_tres -d /var/lib/las_tres -u {{UID}}
|
||||
RUN mkdir -p /var/lib/las_tres/LasTres
|
||||
RUN chown -R las_tres:las_tres /var/lib/las_tres/LasTres
|
||||
USER las_tres
|
||||
|
||||
ENTRYPOINT ["/var/lib/las_tres/LasTres/docker/entrypoint.sh"]
|
26
docker/entrypoint.sh
Executable file
26
docker/entrypoint.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
cd /var/lib/las_tres/LasTres
|
||||
npm install
|
||||
npx webpack
|
||||
if ! grep PERL5LIB ~/.profile; then
|
||||
perl -Mlocal::lib 2>/dev/null >> ~/.profile ;
|
||||
fi && \
|
||||
source ~/.profile && \
|
||||
rm -fr ~/.cpan && \
|
||||
( echo y && echo reload cpan && echo o conf commit ) | perl -MCPAN -Mlocal::lib -e shell && \
|
||||
perl Build.PL && \
|
||||
./Build installdeps && \
|
||||
if ! [ -f las_tres.yml ]; then
|
||||
cat << EOF > las_tres.yml
|
||||
secrets:
|
||||
- $(pwgen -s 512 1)
|
||||
database:
|
||||
dbname: las_tres
|
||||
hypnotoad:
|
||||
listen:
|
||||
- http://*:3000
|
||||
EOF
|
||||
fi && \
|
||||
npx webpack && \
|
||||
bash build_styles.sh && \
|
||||
perl script/las_tres daemon
|
@ -14,10 +14,12 @@ our $VERSION = $LasTres::Schema::VERSION;
|
||||
|
||||
{
|
||||
my $self;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
if (!defined $self) {
|
||||
$self = $class->SUPER::new(@_);
|
||||
if ( !defined $self ) {
|
||||
$self = $class->SUPER::new(
|
||||
Mojo::URL->new->host("/var/run/redis/redis.sock") );
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
@ -27,25 +29,28 @@ sub prefix {
|
||||
return "LasTres::Redis::$VERSION";
|
||||
}
|
||||
|
||||
sub subscribe($self, $topic, $callback) {
|
||||
$self->pubsub->listen($topic, sub($self, $message, $topic) {
|
||||
$callback->($message, $topic, [$topic]);
|
||||
});
|
||||
sub subscribe ( $self, $topic, $callback ) {
|
||||
$self->pubsub->listen(
|
||||
$topic,
|
||||
sub ( $self, $message, $topic ) {
|
||||
$callback->( $message, $topic, [$topic] );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sub publish($self, $topic, $message) {
|
||||
$self->pubsub->notify($topic, $message);
|
||||
sub publish ( $self, $topic, $message ) {
|
||||
$self->pubsub->notify( $topic, $message );
|
||||
}
|
||||
|
||||
sub pj_subscription($class, $pj) {
|
||||
sub pj_subscription ( $class, $pj ) {
|
||||
return prefix() . '::Subscriptions::PJ::' . $pj->uuid;
|
||||
}
|
||||
|
||||
sub battle_key($class, $battle_uuid) {
|
||||
sub battle_key ( $class, $battle_uuid ) {
|
||||
return prefix() . '::Key::Battle' . $battle_uuid;
|
||||
}
|
||||
|
||||
sub executing_frame_key($class) {
|
||||
sub executing_frame_key ($class) {
|
||||
return prefix() . '::Key::Frame';
|
||||
}
|
||||
1;
|
||||
|
38
start_docker.sh
Normal file
38
start_docker.sh
Normal file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENT_DIR=$(dirname $0)
|
||||
NEEDS_SUDO=0
|
||||
SUDO=""
|
||||
DOCKER_TAG="lastres:latest"
|
||||
DOCKER_BUILD_PARAMS="$CURRENT_DIR -t $DOCKER_TAG"
|
||||
DOCKER_RUN_PARAMS="run -it -v /var/run/postgresql/:/var/run/postgresql/ -v $CURRENT_DIR:/var/lib/las_tres/LasTres -v /var/run/redis/:/var/run/redis --name LasTresDocker -p 3000:3000 $DOCKER_TAG"
|
||||
CHECKSUM_DOCKER_FILE="$CURRENT_DIR/.dockerfile_checksum"
|
||||
|
||||
perl -pe 's/\{\{UID\}\}/'"$UID/" Dockerfile.template > Dockerfile
|
||||
|
||||
OLD_CHECKSUM_DOCKER="$(cat $CHECKSUM_DOCKER_FILE 2> /dev/null)"
|
||||
CURRENT_CHECKSUM_DOCKER="$(sha512sum Dockerfile | awk '{ print $1 }')"
|
||||
|
||||
if ! docker image ls 2>/dev/null; then
|
||||
NEEDS_SUDO=1
|
||||
fi
|
||||
|
||||
if [[ $NEEDS_SUDO -gt 0 ]]; then
|
||||
SUDO="sudo"
|
||||
fi
|
||||
|
||||
if [[ $OLD_CHECKSUM_DOCKER != $CURRENT_CHECKSUM_DOCKER ]]; then
|
||||
echo "$OLD_CHECKSUM_DOCKER != $CURRENT_CHECKSUM_DOCKER rebuilding docker";
|
||||
|
||||
echo $SUDO docker build $DOCKER_BUILD_PARAMS
|
||||
$SUDO docker build $DOCKER_BUILD_PARAMS
|
||||
echo $CURRENT_CHECKSUM_DOCKER > $CHECKSUM_DOCKER_FILE
|
||||
echo $SUDO docker $DOCKER_RUN_PARAMS
|
||||
$SUDO docker $DOCKER_RUN_PARAMS
|
||||
exit
|
||||
fi
|
||||
echo $SUDO docker container start LasTresDocker -ai
|
||||
if ! $SUDO docker container start LasTresDocker -ai; then
|
||||
echo $SUDO docker $DOCKER_RUN_PARAMS
|
||||
$SUDO docker $DOCKER_RUN_PARAMS
|
||||
fi
|
Loading…
Reference in New Issue
Block a user