From d9ce4586c4358201e7befdc7eb21b3c9343f2b47 Mon Sep 17 00:00:00 2001
From: Naufal Alauddin Hilmi <naufal.alauddin@ui.ac.id>
Date: Wed, 30 Nov 2022 22:14:35 +0700
Subject: [PATCH] build and deploy as static binary

---
 .gitlab-ci.yml  |  3 +++
 Dockerfile      | 13 +++-------
 flyio.cabal     | 25 +++++++++---------
 stack.yaml      | 67 -------------------------------------------------
 stack.yaml.lock | 13 ----------
 5 files changed, 20 insertions(+), 101 deletions(-)
 delete mode 100644 stack.yaml
 delete mode 100644 stack.yaml.lock

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7e24c5f..9c06884 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,7 +5,10 @@ default:
     - export FLYCTL_INSTALL="/root/.fly" && export PATH="$FLYCTL_INSTALL/bin:$PATH"
 
 deploy:
+  image: utdemir/ghc-musl:v24-ghc8107
   script:
+    - cabal build exe:myapp --enable-executable-static --enable-executable-stripping
+    - cabal install installdir=. --enable-executable-static --enable-executable-stripping
     - flyctl deploy
   only:
     - tags
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index 9e1467f..d747b4a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,10 +1,5 @@
-FROM haskell:9.2-slim
-RUN cabal update
+FROM alpine
 EXPOSE 8080
-COPY flyio.cabal .
-COPY CHANGELOG.md .
-RUN cabal build --dependencies-only
-COPY app ./app
-COPY src ./src
-RUN cabal install exe:flyio
-ENTRYPOINT [ "flyio" ]
\ No newline at end of file
+RUN apk add gmp
+COPY myapp myapp
+ENTRYPOINT [ "./myapp" ]
\ No newline at end of file
diff --git a/flyio.cabal b/flyio.cabal
index 8f56a27..f70cf99 100644
--- a/flyio.cabal
+++ b/flyio.cabal
@@ -33,17 +33,18 @@ library
     -- LANGUAGE extensions used by modules in this package.
     -- other-extensions:
     build-depends:
-        aeson,
-        base ^>=4.16.3.0,
-        containers,
-        servant,
-        servant-server,
-        mtl,
-        text
+       aeson,
+       base,
+       containers,
+       servant,
+       servant-server,
+       mtl,
+       text,
+       time
     hs-source-dirs:   src
     default-language: Haskell2010
 
-executable flyio
+executable myapp
     main-is:          Main.hs
 
     -- Modules included in this executable, other than Main.
@@ -52,10 +53,10 @@ executable flyio
     -- LANGUAGE extensions used by modules in this package.
     -- other-extensions:
     build-depends:
-        base ^>=4.16.3.0,
-        containers,
-        flyio,
-        warp
+       base,
+       containers,
+       flyio,
+       warp
 
     hs-source-dirs:   app
     default-language: Haskell2010
diff --git a/stack.yaml b/stack.yaml
deleted file mode 100644
index 12080c0..0000000
--- a/stack.yaml
+++ /dev/null
@@ -1,67 +0,0 @@
-# This file was automatically generated by 'stack init'
-#
-# Some commonly used options have been documented as comments in this file.
-# For advanced use and comprehensive documentation of the format, please see:
-# https://docs.haskellstack.org/en/stable/yaml_configuration/
-
-# Resolver to choose a 'specific' stackage snapshot or a compiler version.
-# A snapshot resolver dictates the compiler version and the set of packages
-# to be used for project dependencies. For example:
-#
-# resolver: lts-3.5
-# resolver: nightly-2015-09-21
-# resolver: ghc-7.10.2
-#
-# The location of a snapshot can be provided as a file or url. Stack assumes
-# a snapshot provided as a file might change, whereas a url resource does not.
-#
-# resolver: ./custom-snapshot.yaml
-# resolver: https://example.com/snapshots/2018-01-01.yaml
-resolver:
-  url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/11/3.yaml
-
-# User packages to be built.
-# Various formats can be used as shown in the example below.
-#
-# packages:
-# - some-directory
-# - https://example.com/foo/bar/baz-0.0.2.tar.gz
-#   subdirs:
-#   - auto-update
-#   - wai
-packages:
-- .
-# Dependency packages to be pulled from upstream that are not in the resolver.
-# These entries can reference officially published versions as well as
-# forks / in-progress versions pinned to a git hash. For example:
-#
-# extra-deps:
-# - acme-missiles-0.3
-# - git: https://github.com/commercialhaskell/stack.git
-#   commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
-#
-# extra-deps: []
-
-# Override default flag values for local packages and extra-deps
-# flags: {}
-
-# Extra package databases containing global packages
-# extra-package-dbs: []
-
-# Control whether we use the GHC we find on the path
-# system-ghc: true
-#
-# Require a specific version of stack, using version ranges
-# require-stack-version: -any # Default
-# require-stack-version: ">=2.7"
-#
-# Override the architecture used by stack, especially useful on Windows
-# arch: i386
-# arch: x86_64
-#
-# Extra directories used by stack for building
-# extra-include-dirs: [/path/to/dir]
-# extra-lib-dirs: [/path/to/dir]
-#
-# Allow a newer minor version of GHC than the snapshot specifies
-# compiler-check: newer-minor
diff --git a/stack.yaml.lock b/stack.yaml.lock
deleted file mode 100644
index c870e65..0000000
--- a/stack.yaml.lock
+++ /dev/null
@@ -1,13 +0,0 @@
-# This file was autogenerated by Stack.
-# You should not edit this file by hand.
-# For more information, please see the documentation at:
-#   https://docs.haskellstack.org/en/stable/lock_files
-
-packages: []
-snapshots:
-- completed:
-    size: 646690
-    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/11/3.yaml
-    sha256: 5201b267da5c16bde723e0401eed332c96035edd55250a947089a7d9417b7ecc
-  original:
-    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/11/3.yaml
-- 
GitLab