Skip to content

Commit

Permalink
Merge pull request #11 from Alistair1231/docker-support
Browse files Browse the repository at this point in the history
add docker support
  • Loading branch information
dgl authored Jul 2, 2024
2 parents b22b339 + fa9e823 commit 9fdffe6
Show file tree
Hide file tree
Showing 8 changed files with 561 additions and 4 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
69 changes: 69 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -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';
Loading

0 comments on commit 9fdffe6

Please sign in to comment.