Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 81c885c

Browse files
authored
added basic api call functionality (#4)
* added basic api call functionality * dont throw execptions, get reponse values * handle status codes * upload of one file works * basic download functionality * use a stack project instead of a single file, this enables typechecking * use a stack project instead of a single file, this enables typechecking * remove old main file * cleanup arg handlign * added build pipeline and docker image * change readme * minor chnges on profile and headers * only use json, add header for filesize * add mimetype * add mimetype * refactor rest response type * add feature release workflow * upload file to /tmp an not to memory * tweak dockerfile for security and logging * prepare deployemnt * change rest port * needs more cow bell * fix url handling * added deleteEndpoint (wip) * setup for tests * delete endpoint working * added more headers and health endpoint * prepare downlaod endpoint * added zipping of files for downloading * use temporary file also for deleting * change return type of upload endpoint, extend health * add more error handling * Format the code * add stage profile * make mimetype as possible null value, (clean this up later) * cleanup, add stable pipeline * add possible null values * fix pipeline name, dont run feature pipeline all the time
1 parent 1933cb6 commit 81c885c

File tree

15 files changed

+759
-536
lines changed

15 files changed

+759
-536
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Feature Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'featureWithPipeline/**'
8+
paths:
9+
- 'app/**'
10+
- 'src/**'
11+
- 'test/**'
12+
13+
jobs:
14+
Build_Docker_Image_on_Push:
15+
runs-on: ubuntu-latest
16+
steps:
17+
-
18+
name: Set up Project
19+
uses: actions/checkout@v2
20+
-
21+
name: Build Filehandler
22+
run: |
23+
stack build
24+
25+
-
26+
name: Login to DockerHub
27+
uses: docker/login-action@v1
28+
with:
29+
username: ${{ secrets.DOCKER_USER }}
30+
password: ${{ secrets.DOCKER_PW }}
31+
-
32+
name: Build and push
33+
run: |
34+
BINLOCATION=$(stack path --local-install-root)
35+
BINLOCATION=$(realpath --relative-to=. $BINLOCATION)
36+
docker build -t filefighter/filehandler:feature . --build-arg BINLOCATION=$BINLOCATION
37+
docker push filefighter/filehandler:feature
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Latest Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: "master"
7+
paths:
8+
- 'app/**'
9+
- 'src/**'
10+
- 'test/**'
11+
12+
jobs:
13+
Build_Docker_Image_on_Push:
14+
runs-on: ubuntu-latest
15+
steps:
16+
-
17+
name: Set up Project
18+
uses: actions/checkout@v2
19+
-
20+
name: Build Filehandler
21+
run: |
22+
stack build
23+
24+
-
25+
name: Login to DockerHub
26+
uses: docker/login-action@v1
27+
with:
28+
username: ${{ secrets.DOCKER_USER }}
29+
password: ${{ secrets.DOCKER_PW }}
30+
-
31+
name: Build and push
32+
run: |
33+
BINLOCATION=$(stack path --local-install-root)
34+
BINLOCATION=$(realpath --relative-to=. $BINLOCATION)
35+
docker build -t filefighter/filehandler:latest . --build-arg BINLOCATION=$BINLOCATION
36+
docker push filefighter/filehandler:latest
37+
-
38+
name: Trigger update on server
39+
run:
40+
- curl -u ${{ secrets.LOG_CREDS }} https://logs.filefighter.de/filefighter-update.log
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Stable Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
Build_Docker_Image_on_Push:
10+
runs-on: ubuntu-latest
11+
steps:
12+
-
13+
name: Set up Project
14+
uses: actions/checkout@v2
15+
-
16+
name: Build Filehandler
17+
run: |
18+
stack build
19+
20+
-
21+
name: Login to DockerHub
22+
uses: docker/login-action@v1
23+
with:
24+
username: ${{ secrets.DOCKER_USER }}
25+
password: ${{ secrets.DOCKER_PW }}
26+
-
27+
name: Build and push
28+
run: |
29+
VERSION=${{ steps.vars.outputs.tag }}
30+
BINLOCATION=$(stack path --local-install-root)
31+
BINLOCATION=$(realpath --relative-to=. $BINLOCATION)
32+
docker build -t filefighter/filehandler:$VERSION -t filefighter/filehandler:stable . --build-arg BINLOCATION=$BINLOCATION
33+
docker push filefighter/filehandler:$VERSION
34+
docker push filefighter/filehandler:stable

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog for Filehandler
2+
3+
## Unreleased changes

Dockerfile

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
1-
FROM ubuntu:16.04
1+
FROM ubuntu:latest
22

3-
# Get dumb-init to avoid Ctrl-C issues. See:
4-
# http://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html
5-
ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.3/dumb-init_1.1.3_amd64 /usr/local/bin/dumb-init
6-
RUN chmod +x /usr/local/bin/dumb-init
3+
ARG BINLOCATION
4+
ENV RESTURL=FileFighterREST
5+
ENV PROFILE=prod
76

8-
# Set up Haskell Stack, the Haskell build tool.
9-
# Stack is the only dependency we have to run our application.
10-
# Once available, it will grab everything else we need
11-
# (compiler, libraries, etc).
12-
ADD https://get.haskellstack.org/get-stack.sh /usr/local/bin/
13-
RUN sh /usr/local/bin/get-stack.sh
7+
RUN apt-get update && apt-get upgrade -y
148

159
# Copy over the source code and make it executable.
16-
COPY FileHandler.hs /usr/local/bin/file-handler
17-
RUN chmod +x /usr/local/bin/file-handler
10+
ADD $BINLOCATION/bin/Filehandler-exe /usr/local/bin/filehandler-exe
11+
RUN chmod +x /usr/local/bin/filehandler-exe
1812

19-
# Create a new user account and directory to run from, and then
20-
# run everything else as that user.
21-
RUN useradd -m www && mkdir -p /workdir && chown www /workdir
22-
USER www
23-
24-
# We run our application with "sanity" to force it to install all of
25-
# its dependencies during Docker image build time, making the Docker
26-
# image launch much faster.
27-
RUN /usr/local/bin/file-handler sanity
13+
# TODO: because we want to write to a host directory we must run as root, or change the permissions of the directory
14+
# create group and user, then the working dir and add permissions to it
15+
#RUN groupadd -g 999 appuser && useradd -r -u 999 -g appuser appuser && mkdir -p /workdir && chown appuser /workdir
16+
#USER appuser
2817

2918
# We're all ready, now just configure our image to run the server on
3019
# launch from the correct working directory.
31-
CMD ["/usr/local/bin/dumb-init", "/usr/local/bin/file-handler"]
20+
# using exec solves ctl + c issues
21+
CMD exec /usr/local/bin/filehandler-exe ${RESTURL} $PROFILE
3222
WORKDIR /workdir
3323
EXPOSE 5000

FileHandler.hs

Lines changed: 0 additions & 143 deletions
This file was deleted.

Filehandler.cabal

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
cabal-version: 1.12
2+
3+
-- This file has been generated from package.yaml by hpack version 0.33.0.
4+
--
5+
-- see: https://github.com/sol/hpack
6+
--
7+
-- hash: 810c23ddfee0d410c3632560ab726ca5db1e957ed8095989f8e2e7e554eb65f4
8+
9+
name: Filehandler
10+
version: 0.1.0.0
11+
description: Please see the README on GitHub at <https://github.com/githubuser/Filehandler#readme>
12+
homepage: https://github.com/githubuser/Filehandler#readme
13+
bug-reports: https://github.com/githubuser/Filehandler/issues
14+
author: Author name here
15+
maintainer: [email protected]
16+
copyright: 2021 Author name here
17+
license: BSD3
18+
license-file: LICENSE
19+
build-type: Simple
20+
extra-source-files:
21+
README.md
22+
ChangeLog.md
23+
24+
source-repository head
25+
type: git
26+
location: https://github.com/FileFighter/Filehandler
27+
28+
library
29+
exposed-modules:
30+
Lib
31+
other-modules:
32+
Paths_Filehandler
33+
hs-source-dirs:
34+
src
35+
build-depends:
36+
base >=4.7 && <5
37+
default-language: Haskell2010
38+
39+
executable Filehandler-exe
40+
main-is: Main.hs
41+
other-modules:
42+
Paths_Filehandler
43+
hs-source-dirs:
44+
app
45+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
46+
build-depends:
47+
Filehandler
48+
, base >=4.7 && <5
49+
, req
50+
, wai
51+
, wai-app-static
52+
, wai-extra
53+
, wai-cors
54+
, warp
55+
, network
56+
, text
57+
, aeson
58+
, filepath
59+
, http-types
60+
, bytestring
61+
, directory
62+
, case-insensitive
63+
, mtl
64+
, resourcet
65+
, zip
66+
, temporary
67+
default-language: Haskell2010
68+
69+
test-suite Filehandler-test
70+
type: exitcode-stdio-1.0
71+
main-is: Spec.hs
72+
other-modules:
73+
Paths_Filehandler
74+
hs-source-dirs:
75+
test
76+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
77+
build-depends:
78+
Filehandler
79+
, base >=4.7 && <5
80+
, hspec
81+
, QuickCheck
82+
default-language: Haskell2010

0 commit comments

Comments
 (0)