diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..386f918 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,35 @@ +name: Docker +on: + push: + branches: + - "*" + + tags: + - "v*" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Build image + run: docker buildx build --cache-to type=gha --cache-from type=gha -t image . + + - name: Push image + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + GITHUB_ID="ghcr.io/${{ github.repository }}" + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' -e 's,^v,,') + + # Use Docker `latest` tag convention + [ "$VERSION" == "main" ] && VERSION=latest + + set -x + + docker tag image $GITHUB_ID:$VERSION + docker push $GITHUB_ID:$VERSION diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..156920e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM perl:stable AS deps-test + +RUN cpanm Carton +COPY cpanfile . +COPY cpanfile.snapshot . +RUN carton install && carton bundle + +FROM perl:stable +COPY . . + +COPY --from=deps-test /usr/src/app/vendor/ ./vendor +# Use version requirements from above, remove build artifacts after +RUN cpanm --notest --from "$PWD/vendor/cache" --installdeps . && rm -rf ~/.cpanm vendor/ + +# This image needs a secret of 'serverauth' and a volume mounted at '/db'. +RUN ln -sf /run/secrets/serverauth && ln -sf /db + +EXPOSE 5000 +CMD ["./run-docker.sh"] diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..5637044 --- /dev/null +++ b/compose.yml @@ -0,0 +1,69 @@ +# Docker compose file to run paste.sh locally. +# +# Optional, build (the image is published): +# docker-compose build +# +# docker-compose --profile update-misc up +# +# Then visit http://localhost:5000 + +services: + serverauth: + image: davidgl/pastesh + entrypoint: ["/bin/bash", "-c", "./generate-serverauth /work/serverauth"] + volumes: + - .:/work + + pastesh: + depends_on: + serverauth: + condition: service_completed_successfully + build: + context: . + dockerfile: Dockerfile + image: davidgl/pastesh + restart: unless-stopped + # if you use a reverse proxy container, you can remove the port mapping. + ports: + - "5000:5000" + volumes: + - paste-db:/db + secrets: + - serverauth + healthcheck: + test: curl localhost:5000 + start_period: 10s + interval: 10s + timeout: 2s + retries: 3 + # if use a reverse proxy container, you can uncomment the networks sections here, and below. + #networks: + # - apps + + update-misc: + image: davidgl/pastesh + # Use docker-compose --profile update-misc up to run this, note this will + # use whatever is in davidgl/pastesh, so be careful to ensure you've built + # it locally (i.e. docker-compose build), else you'll get the paste.sh + # upstream misc data. + profiles: + - update-misc + restart: no + entrypoint: ["./update-misc"] + depends_on: + pastesh: + condition: service_healthy + network_mode: service:pastesh + secrets: + - serverauth + +#networks: +# apps: +# external: true + +volumes: + paste-db: + +secrets: + serverauth: + file: ./serverauth diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..c3fe41e --- /dev/null +++ b/cpanfile @@ -0,0 +1,11 @@ +requires 'JSON'; +requires 'JSON::XS'; +requires 'Tie::LevelDB'; +requires 'Web::Simple'; +requires 'Plack::Request'; +requires 'Plack::Runner'; +requires 'HTML::Entities'; +requires 'Twiggy'; + +# Build dep of other things; somehow carton doesn't figure it out, so depend on it here... +requires 'Module::Build::Tiny'; diff --git a/cpanfile.snapshot b/cpanfile.snapshot new file mode 100644 index 0000000..f392066 --- /dev/null +++ b/cpanfile.snapshot @@ -0,0 +1,416 @@ +# carton snapshot format: version 1.0 +DISTRIBUTIONS + AnyEvent-7.17 + pathname: M/ML/MLEHMANN/AnyEvent-7.17.tar.gz + provides: + AE undef + AE::Log::COLLECT undef + AE::Log::FILTER undef + AE::Log::LOG undef + AnyEvent 7.17 + AnyEvent::Base 7.17 + AnyEvent::CondVar 7.17 + AnyEvent::CondVar::Base 7.17 + AnyEvent::DNS undef + AnyEvent::Debug undef + AnyEvent::Debug::Backtrace undef + AnyEvent::Debug::Wrap undef + AnyEvent::Debug::Wrapped undef + AnyEvent::Debug::shell undef + AnyEvent::Handle undef + AnyEvent::IO undef + AnyEvent::IO::IOAIO undef + AnyEvent::IO::Perl undef + AnyEvent::Impl::Cocoa undef + AnyEvent::Impl::EV undef + AnyEvent::Impl::Event undef + AnyEvent::Impl::EventLib undef + AnyEvent::Impl::FLTK undef + AnyEvent::Impl::Glib undef + AnyEvent::Impl::IOAsync undef + AnyEvent::Impl::Irssi undef + AnyEvent::Impl::POE undef + AnyEvent::Impl::Perl undef + AnyEvent::Impl::Qt undef + AnyEvent::Impl::Qt::Io undef + AnyEvent::Impl::Qt::Timer undef + AnyEvent::Impl::Tk undef + AnyEvent::Impl::UV undef + AnyEvent::Log undef + AnyEvent::Log::COLLECT undef + AnyEvent::Log::Ctx undef + AnyEvent::Log::FILTER undef + AnyEvent::Log::LOG undef + AnyEvent::Loop undef + AnyEvent::Socket undef + AnyEvent::Strict undef + AnyEvent::TLS undef + AnyEvent::Util undef + requirements: + Canary::Stability 0 + ExtUtils::MakeMaker 6.52 + CPAN-Requirements-Dynamic-0.001 + pathname: L/LE/LEONT/CPAN-Requirements-Dynamic-0.001.tar.gz + provides: + CPAN::Requirements::Dynamic 0.001 + requirements: + CPAN::Meta::Prereqs 0 + CPAN::Meta::Requirements::Range 0 + Carp 0 + ExtUtils::Config 0 + ExtUtils::HasCompiler 0 + ExtUtils::MakeMaker 0 + IPC::Cmd 0 + Module::Metadata 0 + Parse::CPAN::Meta 0 + Perl::OSType 0 + perl 5.006 + strict 0 + warnings 0 + Clone-0.46 + pathname: G/GA/GARU/Clone-0.46.tar.gz + provides: + Clone 0.46 + requirements: + ExtUtils::MakeMaker 0 + ExtUtils-Config-0.009 + pathname: L/LE/LEONT/ExtUtils-Config-0.009.tar.gz + provides: + ExtUtils::Config 0.009 + ExtUtils::Config::MakeMaker 0.009 + requirements: + Data::Dumper 0 + ExtUtils::MakeMaker 0 + ExtUtils::MakeMaker::Config 0 + perl 5.006 + strict 0 + warnings 0 + ExtUtils-HasCompiler-0.025 + pathname: L/LE/LEONT/ExtUtils-HasCompiler-0.025.tar.gz + provides: + ExtUtils::HasCompiler 0.025 + requirements: + Carp 0 + DynaLoader 0 + Exporter 0 + ExtUtils::MakeMaker 0 + ExtUtils::Mksymlists 0 + File::Basename 0 + File::Spec::Functions 0 + File::Temp 0 + base 0 + perl 5.006 + strict 0 + warnings 0 + ExtUtils-Helpers-0.027 + pathname: L/LE/LEONT/ExtUtils-Helpers-0.027.tar.gz + provides: + ExtUtils::Helpers 0.027 + ExtUtils::Helpers::Unix 0.027 + ExtUtils::Helpers::VMS 0.027 + ExtUtils::Helpers::Windows 0.027 + requirements: + Carp 0 + Exporter 5.57 + ExtUtils::MakeMaker 0 + File::Basename 0 + File::Copy 0 + File::Spec::Functions 0 + Text::ParseWords 3.24 + strict 0 + warnings 0 + ExtUtils-InstallPaths-0.013 + pathname: L/LE/LEONT/ExtUtils-InstallPaths-0.013.tar.gz + provides: + ExtUtils::InstallPaths 0.013 + requirements: + Carp 0 + ExtUtils::Config 0.002 + ExtUtils::MakeMaker 0 + File::Spec 0 + perl 5.006 + strict 0 + warnings 0 + HTML-Parser-3.82 + pathname: O/OA/OALDERS/HTML-Parser-3.82.tar.gz + provides: + HTML::Entities 3.82 + HTML::Filter 3.82 + HTML::HeadParser 3.82 + HTML::LinkExtor 3.82 + HTML::Parser 3.82 + HTML::PullParser 3.82 + HTML::TokeParser 3.82 + requirements: + Carp 0 + Exporter 0 + ExtUtils::MakeMaker 6.52 + HTML::Tagset 0 + HTTP::Headers 0 + IO::File 0 + URI 0 + URI::URL 0 + XSLoader 0 + strict 0 + HTTP-Body-1.23 + pathname: G/GE/GETTY/HTTP-Body-1.23.tar.gz + provides: + HTTP::Body 1.23 + HTTP::Body::MultiPart 1.23 + HTTP::Body::OctetStream 1.23 + HTTP::Body::UrlEncoded 1.23 + HTTP::Body::XForms 1.23 + HTTP::Body::XFormsMultipart 1.23 + requirements: + Carp 0 + Digest::MD5 0 + ExtUtils::MakeMaker 0 + File::Temp 0.14 + HTTP::Headers 0 + IO::File 1.14 + HTTP-Message-6.46 + pathname: O/OA/OALDERS/HTTP-Message-6.46.tar.gz + provides: + HTTP::Config 6.46 + HTTP::Headers 6.46 + HTTP::Headers::Auth 6.46 + HTTP::Headers::ETag 6.46 + HTTP::Headers::Util 6.46 + HTTP::Message 6.46 + HTTP::Request 6.46 + HTTP::Request::Common 6.46 + HTTP::Response 6.46 + HTTP::Status 6.46 + requirements: + Carp 0 + Clone 0.46 + Compress::Raw::Bzip2 0 + Compress::Raw::Zlib 2.062 + Encode 3.01 + Encode::Locale 1 + Exporter 5.57 + ExtUtils::MakeMaker 0 + File::Spec 0 + HTTP::Date 6 + IO::Compress::Bzip2 2.021 + IO::Compress::Deflate 0 + IO::Compress::Gzip 0 + IO::HTML 0 + IO::Uncompress::Inflate 0 + IO::Uncompress::RawInflate 0 + LWP::MediaTypes 6 + MIME::Base64 2.1 + MIME::QuotedPrint 0 + URI 1.10 + parent 0 + perl 5.008001 + strict 0 + warnings 0 + JSON-XS-4.03 + pathname: M/ML/MLEHMANN/JSON-XS-4.03.tar.gz + provides: + JSON::XS 4.03 + requirements: + Canary::Stability 0 + ExtUtils::MakeMaker 6.52 + Types::Serialiser 0 + common::sense 0 + Module-Build-Tiny-0.048 + pathname: L/LE/LEONT/Module-Build-Tiny-0.048.tar.gz + provides: + Module::Build::Tiny 0.048 + requirements: + CPAN::Meta 0 + CPAN::Requirements::Dynamic 0 + DynaLoader 0 + Exporter 5.57 + ExtUtils::CBuilder 0 + ExtUtils::Config 0.003 + ExtUtils::Helpers 0.020 + ExtUtils::Install 0 + ExtUtils::InstallPaths 0.002 + ExtUtils::ParseXS 0 + File::Basename 0 + File::Find 0 + File::Path 0 + File::Spec::Functions 0 + Getopt::Long 2.36 + JSON::PP 2 + Pod::Man 0 + TAP::Harness::Env 0 + perl 5.006 + strict 0 + warnings 0 + Plack-1.0051 + pathname: M/MI/MIYAGAWA/Plack-1.0051.tar.gz + provides: + HTTP::Message::PSGI undef + HTTP::Server::PSGI undef + Plack 1.0051 + Plack::App::CGIBin undef + Plack::App::Cascade undef + Plack::App::Directory undef + Plack::App::File undef + Plack::App::PSGIBin undef + Plack::App::URLMap undef + Plack::App::WrapCGI undef + Plack::Builder undef + Plack::Component undef + Plack::HTTPParser undef + Plack::HTTPParser::PP undef + Plack::Handler undef + Plack::Handler::Apache1 undef + Plack::Handler::Apache2 undef + Plack::Handler::Apache2::Registry undef + Plack::Handler::CGI undef + Plack::Handler::CGI::Writer undef + Plack::Handler::FCGI undef + Plack::Handler::HTTP::Server::PSGI undef + Plack::Handler::Standalone undef + Plack::LWPish undef + Plack::Loader undef + Plack::Loader::Delayed undef + Plack::Loader::Restarter undef + Plack::Loader::Shotgun undef + Plack::MIME undef + Plack::Middleware undef + Plack::Middleware::AccessLog undef + Plack::Middleware::AccessLog::Timed undef + Plack::Middleware::Auth::Basic undef + Plack::Middleware::BufferedStreaming undef + Plack::Middleware::Chunked undef + Plack::Middleware::Conditional undef + Plack::Middleware::ConditionalGET undef + Plack::Middleware::ContentLength undef + Plack::Middleware::ContentMD5 undef + Plack::Middleware::ErrorDocument undef + Plack::Middleware::HTTPExceptions undef + Plack::Middleware::Head undef + Plack::Middleware::IIS6ScriptNameFix undef + Plack::Middleware::IIS7KeepAliveFix undef + Plack::Middleware::JSONP undef + Plack::Middleware::LighttpdScriptNameFix undef + Plack::Middleware::Lint undef + Plack::Middleware::Log4perl undef + Plack::Middleware::LogDispatch undef + Plack::Middleware::NullLogger undef + Plack::Middleware::RearrangeHeaders undef + Plack::Middleware::Recursive undef + Plack::Middleware::Refresh undef + Plack::Middleware::Runtime undef + Plack::Middleware::SimpleContentFilter undef + Plack::Middleware::SimpleLogger undef + Plack::Middleware::StackTrace undef + Plack::Middleware::Static undef + Plack::Middleware::XFramework undef + Plack::Middleware::XSendfile undef + Plack::Recursive::ForwardRequest undef + Plack::Request 1.0051 + Plack::Request::Upload undef + Plack::Response 1.0051 + Plack::Runner undef + Plack::TempBuffer undef + Plack::Test undef + Plack::Test::MockHTTP undef + Plack::Test::Server undef + Plack::Test::Suite undef + Plack::Util undef + Plack::Util::Accessor undef + Plack::Util::IOWithPath undef + Plack::Util::Prototype undef + requirements: + Apache::LogFormat::Compiler 0.33 + Cookie::Baker 0.07 + Devel::StackTrace 1.23 + Devel::StackTrace::AsHTML 0.11 + ExtUtils::MakeMaker 0 + File::ShareDir 1.00 + File::ShareDir::Install 0.06 + Filesys::Notify::Simple 0 + HTTP::Entity::Parser 0.25 + HTTP::Headers::Fast 0.18 + HTTP::Message 5.814 + HTTP::Tiny 0.034 + Hash::MultiValue 0.05 + Pod::Usage 1.36 + Stream::Buffered 0.02 + Test::TCP 2.15 + Try::Tiny 0 + URI 1.59 + WWW::Form::UrlEncoded 0.23 + parent 0 + perl 5.012000 + Tie-LevelDB-0.07 + pathname: S/SA/SARFY/Tie-LevelDB-0.07.tar.gz + provides: + Tie::LevelDB 0.07 + requirements: + ExtUtils::MakeMaker 0 + Twiggy-0.1026 + pathname: M/MI/MIYAGAWA/Twiggy-0.1026.tar.gz + provides: + AnyEvent::Server::PSGI undef + Plack::Handler::Twiggy undef + Twiggy 0.1026 + Twiggy::Server undef + Twiggy::Server::SS undef + Twiggy::Writer undef + requirements: + AnyEvent 0 + ExtUtils::MakeMaker 0 + HTTP::Status 0 + Plack 0.99 + Try::Tiny 0 + perl 5.008001 + WWW-Form-UrlEncoded-0.26 + pathname: K/KA/KAZEBURO/WWW-Form-UrlEncoded-0.26.tar.gz + provides: + WWW::Form::UrlEncoded 0.26 + WWW::Form::UrlEncoded::PP undef + requirements: + Exporter 0 + Module::Build 0.4005 + perl 5.008001 + Web-Simple-0.033 + pathname: M/MS/MSTROUT/Web-Simple-0.033.tar.gz + provides: + CSS::Declare undef + CSS::Declare::Unex undef + HTML::Tags undef + Plack::Middleware::Dispatch undef + Web::Dispatch undef + Web::Dispatch::HTTPMethods undef + Web::Dispatch::HTTPMethods::Endpoint undef + Web::Dispatch::Node undef + Web::Dispatch::NotAnUpload undef + Web::Dispatch::ParamParser undef + Web::Dispatch::Parser undef + Web::Dispatch::Predicates undef + Web::Dispatch::ToApp undef + Web::Dispatch::Upload undef + Web::Dispatch::Wrapper undef + Web::Simple 0.033 + Web::Simple::Application undef + Web::Simple::Role 0.033 + XML::Tags undef + XML::Tags::StringThing undef + XML::Tags::TIEHANDLE undef + XML::Tags::Unex undef + requirements: + Encode 0 + Exporter 5.57 + ExtUtils::MakeMaker 0 + HTTP::Body 1.22 + Moo 0.009014 + Plack 0.9968 + Scalar::Util 0 + Syntax::Keyword::Gather 1.001 + perl 5.006 + strictures 1 + warnings::illegalproto 0 + common-sense-3.75 + pathname: M/ML/MLEHMANN/common-sense-3.75.tar.gz + provides: + common::sense 3.75 + requirements: + ExtUtils::MakeMaker 0 diff --git a/generate-serverauth b/generate-serverauth new file mode 100755 index 0000000..9bbdaf5 --- /dev/null +++ b/generate-serverauth @@ -0,0 +1,6 @@ +#!/bin/bash +out="${1:-serverauth}" +if [[ ! -s "$out" ]]; then + openssl rand -base64 32 > "$out" +fi +[[ -s $out ]] diff --git a/run-docker.sh b/run-docker.sh new file mode 100755 index 0000000..26c071e --- /dev/null +++ b/run-docker.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec twiggy --listen :5000 diff --git a/run.sh b/run.sh index e26a99f..4e162d1 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,3 @@ -#!/bin/bash -[[ -f deps/bin/twiggy ]] || \ - cpanm -l deps JSON JSON::XS Tie::LevelDB Web::Simple Plack::Request Twiggy -exec deps/bin/twiggy -Ideps/lib/perl5 --listen 127.0.0.1:5000 +#!/usr/bin/env bash +[[ -f local/bin/twiggy ]] || carton +exec carton exec twiggy --listen 127.0.0.1:5000