From 728e6452b35e2f7736beed42b80661a8a663b563 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 13 Aug 2022 18:16:32 +0200 Subject: [PATCH 1/4] Add Docker support Instructions for how to build & use it added to README.md Add GitHub workflow to publishing the docker image to the GitHub Container Repository --- .github/workflows/docker-publish.yml | 66 ++++++++++++++++++++++++++++ Dockerfile | 9 ++++ README.md | 18 ++++++++ 3 files changed, 93 insertions(+) create mode 100644 .github/workflows/docker-publish.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..e51e778 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,66 @@ +--- +name: Docker + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Run tests + run: docker build . --file Dockerfile + + push: + needs: test + if: ${{ github.event_name != 'pull_request' }} + permissions: + contents: read + packages: write + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Log into GitHub Container Registry + uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..22ddb90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:alpine as build +WORKDIR /app +COPY . . +RUN go build + +FROM alpine:latest +COPY --from=build /app/jaf /app/jaf +WORKDIR /app +CMD ["./jaf"] diff --git a/README.md b/README.md index 69e0425..0070e64 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,24 @@ jaf -configFile example.conf ``` Of course, you can also write a init system script to handle this for you. +### Running from Docker +Running it from the GitHub Container Registry +```bash +docker run \ + -v /path/to/your/config.conf:/app/jaf.conf \ + -v /path/to/where/you/want/your/files/to/be/stored:/FileDir/in/your/config \ + ghcr.io/leon-richardt/jaf:latest +``` + +Building the Docker image and running it locally +```bash +docker build -t jaf . +docker run \ + -v /path/to/your/config.conf:/app/jaf.conf \ + -v /path/to/where/you/want/your/files/to/be/stored:/FileDir/in/your/config \ + jaf +``` + ## Usage You can use jaf with any application that can send POST requests (e.g. ShareX/ShareNix or just `curl`). Make sure the file you want to upload is attached as a `multipart/form-data` field named `file`. From ae33975668e3fb85a3141b9b0c60badcf81bfaba Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 13 Aug 2022 21:06:49 +0200 Subject: [PATCH 2/4] Rename docker-publish workflow jobs --- .github/workflows/docker-publish.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index e51e778..3897712 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -21,19 +21,19 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - # Run tests. - # See also https://docs.docker.com/docker-hub/builds/automated-testing/ - test: + # Build Docker image + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Run tests + - name: Build Docker image run: docker build . --file Dockerfile + # Publish built Docker image to the configured registry push: - needs: test + needs: build if: ${{ github.event_name != 'pull_request' }} permissions: contents: read From 5cec67bfdbe0e423b01b98c950369b87336c6ea4 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 13 Aug 2022 21:39:09 +0200 Subject: [PATCH 3/4] Add port publishing with some documentation --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 0070e64..6be0c63 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ Of course, you can also write a init system script to handle this for you. Running it from the GitHub Container Registry ```bash docker run \ + -p 4712:4711 \ -v /path/to/your/config.conf:/app/jaf.conf \ -v /path/to/where/you/want/your/files/to/be/stored:/FileDir/in/your/config \ ghcr.io/leon-richardt/jaf:latest @@ -67,11 +68,15 @@ Building the Docker image and running it locally ```bash docker build -t jaf . docker run \ + -p 4712:4711 \ -v /path/to/your/config.conf:/app/jaf.conf \ -v /path/to/where/you/want/your/files/to/be/stored:/FileDir/in/your/config \ jaf ``` +Port 4711 is the default port for the server in `example.conf`, if you've changed this in your config you'll need to change this in the `docker run` invocations above too. +The above runs forwards the jaf port from 4711 in the container to 4712 on your local system. + ## Usage You can use jaf with any application that can send POST requests (e.g. ShareX/ShareNix or just `curl`). Make sure the file you want to upload is attached as a `multipart/form-data` field named `file`. From e945a57a55536623260fd2244f39e39086228132 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 14 Aug 2022 13:28:58 +0200 Subject: [PATCH 4/4] Create default FileDir directory in Dockerfile --- Dockerfile | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 22ddb90..a13bfd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,5 @@ RUN go build FROM alpine:latest COPY --from=build /app/jaf /app/jaf WORKDIR /app +RUN mkdir -p /var/www/jaf CMD ["./jaf"] diff --git a/README.md b/README.md index 6be0c63..491c308 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Running it from the GitHub Container Registry docker run \ -p 4712:4711 \ -v /path/to/your/config.conf:/app/jaf.conf \ - -v /path/to/where/you/want/your/files/to/be/stored:/FileDir/in/your/config \ + -v /path/to/local/filedir:/var/www/jaf \ ghcr.io/leon-richardt/jaf:latest ``` @@ -70,7 +70,7 @@ docker build -t jaf . docker run \ -p 4712:4711 \ -v /path/to/your/config.conf:/app/jaf.conf \ - -v /path/to/where/you/want/your/files/to/be/stored:/FileDir/in/your/config \ + -v /path/to/local/filedir:/var/www/jaf \ jaf ```