Skip to content

Commit

Permalink
Now builds but has problems with ca-certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
The1Penguin committed Mar 14, 2023
1 parent 982bdb8 commit a36db6e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 18 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker

on:
push:
tags: ["v*.*.*"]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: build-and-push
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from haskell:9.4.4-slim as build
workdir /app

copy . ./

run cabal update && \
cabal build -j4 && \
cabal install --install-method=copy --installdir . --overwrite-policy=always

from debian:11.6-slim
workdir /app

run apt update && apt install -y libgmp10

copy --from=build /app/dtek.link .

env API=localhost

expose 3000
cmd "./dtek.link"
23 changes: 7 additions & 16 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@
module Main where

import Web.Scotty hiding (Options)
import WithCli
import Network.Wai.Middleware.RequestLogger
import Network.Wai.Middleware.Cors
import Control.Monad.IO.Class
import Network.HTTP.Types.Status
import Data.Aeson hiding (Options)
import Data.Aeson.Types hiding (Options)
import Data.Text.Internal.Lazy
import Data.Text hiding (Text, head, filter)
import Network.HTTP.Simple
import GHC.Generics hiding (to, from)

data Options = Options
{
port :: Int
, apiURL :: String
} deriving (Show, Generic, HasArguments)
import Network.HTTP.Simple
import System.Environment (getEnv)

data Redirects = Redirects
{
Expand All @@ -37,7 +32,7 @@ instance FromJSON Redirects where
prependFailure "parsing JSONResponse failed, "
(typeMismatch "Object" invalid)

data Data = Data {redirs :: [Redirects]}
newtype Data = Data {redirs :: [Redirects]}
deriving (Show, Generic)

instance FromJSON Data where
Expand All @@ -64,13 +59,9 @@ routes address = do

fetchRedirs :: String -> IO [Redirects]
fetchRedirs address = do
request <- parseRequest address
res <- httpJSON request
req <- parseRequest address
res <- httpJSON req
return $ redirs (getResponseBody res :: Data)

main :: IO ()
main = withCli run

run :: Options -> IO ()
run (Options port api) =
scotty port $ routes api
main = scotty 3000 . routes =<< getEnv "API"
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.7'

services:
link:
build: .
restart: unless-stopped
environment:
- API=https://cms.dhack.se/items/links
ports:
- "3000:3000"
3 changes: 1 addition & 2 deletions dtek-link.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ executable dtek.link

-- Other library packages from which modules are imported.
build-depends: aeson >=2.1.2.1
, base ^>=4.17.0.0
, base ^>=4.17.0.0 && <4.18
, bytestring >= 0.11.3.1
, getopt-generics >=0.13.1.0
, http-conduit >=2.3.8
, http-types >= 0.12.3
, scotty >=0.12.1
Expand Down

0 comments on commit a36db6e

Please sign in to comment.