/ nix / script / exe / crane-pull.hs
crane-pull.hs
 1  {-# LANGUAGE OverloadedStrings #-}
 2  
 3  {- |
 4  Pull and extract an OCI container image.
 5  
 6  Usage: oci-pull IMAGE [OUTPUT_DIR]
 7  
 8  Example: oci-pull alpine:latest ./rootfs
 9  -}
10  module Main where
11  
12  import Aleph.Script hiding (FilePath)
13  import qualified Aleph.Script.Tools.Crane as Crane
14  import System.Environment (getArgs)
15  
16  main :: IO ()
17  main = do
18      args <- getArgs
19      case args of
20          [] -> script $ usage
21          [image] -> script $ pullImage image "."
22          [image, output] -> script $ pullImage image output
23          _ -> script $ usage
24    where
25      usage = do
26          echoErr "Usage: oci-pull IMAGE [OUTPUT_DIR]"
27          echoErr ""
28          echoErr "Pull and extract an OCI image to a directory."
29          echoErr ""
30          echoErr "Examples:"
31          echoErr "  oci-pull alpine:latest              # extract to current dir"
32          echoErr "  oci-pull alpine:latest ./rootfs     # extract to ./rootfs"
33          exit 1
34  
35      pullImage image output = do
36          let imageText = pack image
37  
38          -- Set SSL cert
39          setEnv "SSL_CERT_FILE" "/etc/ssl/certs/ca-bundle.crt"
40  
41          echoErr $ ":: Pulling " <> imageText
42          Crane.exportToDir Crane.defaults imageText output
43          echoErr $ ":: Extracted to " <> pack output