diff --git a/.github/workflows/featureRelease.yml b/.github/workflows/featureRelease.yml new file mode 100644 index 0000000..46ad3fd --- /dev/null +++ b/.github/workflows/featureRelease.yml @@ -0,0 +1,37 @@ +name: Feature Release + +on: + workflow_dispatch: + push: + branches: + - 'featureWithPipeline/**' + paths: + - 'app/**' + - 'src/**' + - 'test/**' + +jobs: + Build_Docker_Image_on_Push: + runs-on: ubuntu-latest + steps: + - + name: Set up Project + uses: actions/checkout@v2 + - + name: Build Filehandler + run: | + stack build + + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PW }} + - + name: Build and push + run: | + BINLOCATION=$(stack path --local-install-root) + BINLOCATION=$(realpath --relative-to=. $BINLOCATION) + docker build -t filefighter/filehandler:feature . --build-arg BINLOCATION=$BINLOCATION + docker push filefighter/filehandler:feature \ No newline at end of file diff --git a/.github/workflows/latestRelease.yml b/.github/workflows/latestRelease.yml new file mode 100644 index 0000000..8663d34 --- /dev/null +++ b/.github/workflows/latestRelease.yml @@ -0,0 +1,40 @@ +name: Latest Release + +on: + workflow_dispatch: + push: + branches: "master" + paths: + - 'app/**' + - 'src/**' + - 'test/**' + +jobs: + Build_Docker_Image_on_Push: + runs-on: ubuntu-latest + steps: + - + name: Set up Project + uses: actions/checkout@v2 + - + name: Build Filehandler + run: | + stack build + + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PW }} + - + name: Build and push + run: | + BINLOCATION=$(stack path --local-install-root) + BINLOCATION=$(realpath --relative-to=. $BINLOCATION) + docker build -t filefighter/filehandler:latest . --build-arg BINLOCATION=$BINLOCATION + docker push filefighter/filehandler:latest + - + name: Trigger update on server + run: + - curl -u ${{ secrets.LOG_CREDS }} https://logs.filefighter.de/filefighter-update.log \ No newline at end of file diff --git a/.github/workflows/stableRelease.yml b/.github/workflows/stableRelease.yml new file mode 100644 index 0000000..965f90f --- /dev/null +++ b/.github/workflows/stableRelease.yml @@ -0,0 +1,34 @@ +name: Stable Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + Build_Docker_Image_on_Push: + runs-on: ubuntu-latest + steps: + - + name: Set up Project + uses: actions/checkout@v2 + - + name: Build Filehandler + run: | + stack build + + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PW }} + - + name: Build and push + run: | + VERSION=${{ steps.vars.outputs.tag }} + BINLOCATION=$(stack path --local-install-root) + BINLOCATION=$(realpath --relative-to=. $BINLOCATION) + docker build -t filefighter/filehandler:$VERSION -t filefighter/filehandler:stable . --build-arg BINLOCATION=$BINLOCATION + docker push filefighter/filehandler:$VERSION + docker push filefighter/filehandler:stable \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..3e2c396 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,3 @@ +# Changelog for Filehandler + +## Unreleased changes diff --git a/Dockerfile b/Dockerfile index d94c63d..8936738 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,23 @@ -FROM ubuntu:16.04 +FROM ubuntu:latest -# Get dumb-init to avoid Ctrl-C issues. See: -# http://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html -ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.3/dumb-init_1.1.3_amd64 /usr/local/bin/dumb-init -RUN chmod +x /usr/local/bin/dumb-init +ARG BINLOCATION +ENV RESTURL=FileFighterREST +ENV PROFILE=prod -# Set up Haskell Stack, the Haskell build tool. -# Stack is the only dependency we have to run our application. -# Once available, it will grab everything else we need -# (compiler, libraries, etc). -ADD https://get.haskellstack.org/get-stack.sh /usr/local/bin/ -RUN sh /usr/local/bin/get-stack.sh +RUN apt-get update && apt-get upgrade -y # Copy over the source code and make it executable. -COPY FileHandler.hs /usr/local/bin/file-handler -RUN chmod +x /usr/local/bin/file-handler +ADD $BINLOCATION/bin/Filehandler-exe /usr/local/bin/filehandler-exe +RUN chmod +x /usr/local/bin/filehandler-exe -# Create a new user account and directory to run from, and then -# run everything else as that user. -RUN useradd -m www && mkdir -p /workdir && chown www /workdir -USER www - -# We run our application with "sanity" to force it to install all of -# its dependencies during Docker image build time, making the Docker -# image launch much faster. -RUN /usr/local/bin/file-handler sanity +# TODO: because we want to write to a host directory we must run as root, or change the permissions of the directory +# create group and user, then the working dir and add permissions to it +#RUN groupadd -g 999 appuser && useradd -r -u 999 -g appuser appuser && mkdir -p /workdir && chown appuser /workdir +#USER appuser # We're all ready, now just configure our image to run the server on # launch from the correct working directory. -CMD ["/usr/local/bin/dumb-init", "/usr/local/bin/file-handler"] +# using exec solves ctl + c issues +CMD exec /usr/local/bin/filehandler-exe ${RESTURL} $PROFILE WORKDIR /workdir EXPOSE 5000 \ No newline at end of file diff --git a/FileHandler.hs b/FileHandler.hs deleted file mode 100755 index 2988cb7..0000000 --- a/FileHandler.hs +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env stack -{- stack - --resolver lts-6.11 - --install-ghc - runghc - --package shakespeare - --package wai-app-static - --package wai-extra - --package warp - -} - --- The code above is used for Haskell Stack's script interpreter --- feature. For more information, see: --- https://docs.haskellstack.org/en/stable/GUIDE/#script-interpreter --- --- Note how we explicitly list an LTS Haskell snapshot --- (https://www.stackage.org/lts-6.11) to ensure reproducibility. We --- then state which packages need to be present to run this code. - --- Enable the OverloadedStrings extension, a commonly used feature. -{-# LANGUAGE OverloadedStrings #-} - --- We use the QuasiQuotes to embed Hamlet HTML templates inside --- our source file. -{-# LANGUAGE QuasiQuotes #-} - --- Import the various modules that we'll use in our code. -import qualified Data.ByteString.Char8 as S8 -import qualified Data.ByteString.Lazy as L -import Data.Functor.Identity -import Network.HTTP.Types -import Network.Wai -import Network.Wai.Application.Static -import Network.Wai.Handler.Warp -import Network.Wai.Parse -import System.Environment -import System.FilePath -import Text.Blaze.Html.Renderer.Utf8 -import Text.Hamlet - --- | Entrypoint to our application -main :: IO () -main = do - -- For ease of setup, we want to have a "sanity" command line - -- argument. We'll see how this is used in the Dockerfile - -- later. Desired behavior: - -- - -- * If we have the argument "sanity", immediately exit - -- * If we have no arguments, run the server - -- * Otherwise, error out - args <- getArgs - case args of - ["sanity"] -> putStrLn "Sanity check passed, ready to roll!" - [] -> do - putStrLn "Launching DataHandler." - -- Run our application (defined below) on port 5000 - run 5000 app - _ -> error $ "Unknown arguments: " ++ show args - --- | Our main application -app :: Application -app req send = - -- Route the request based on the path requested - case pathInfo req of - -- "/": send the HTML homepage contents - [] -> send $ responseBuilder - status200 - [("Content-Type", "text/html; charset=utf-8")] - (renderHtmlBuilder homepage) - - -- "/browse/...": use the file server to allow directory - -- listings and downloading files - ("browse":rest) -> - -- We create a modified request that strips off the - -- "browse" component of the path, so that the file server - -- does not need to look inside a /browse/ directory - let req' = req { pathInfo = rest } - in fileServer req' send - - -- "/upload": handle a file upload - ["upload"] -> upload req send - - -- anything else: 404 - _ -> send $ responseLBS - status404 - [("Content-Type", "text/plain; charset=utf-8")] - "Not found" - --- | Create an HTML page which links to the /browse URL, and allows --- for a file upload -homepage :: Html -homepage = [shamlet| -$doctype 5 - -
-