Skip to content

Commit

Permalink
Fix hocker-image (#34)
Browse files Browse the repository at this point in the history
* Remove the response integrity check

In commit 63129b1 I removed the check for the function that fetches
layers but did not remove it for the function that fetches a whole
image.

This change is being made because the `Docker-Content-Digest` value
sent back by docker distribution is a hash digest from the image
manifest list when only the image manifest is accepted by the client.

This issue on docker distribution tracks the regression:
distribution/distribution#2395

Fixes #23

Issue #24 tracks reverting this change when the docker distribution
issue is resolved.

This change also fixes a test failure caused by the tests data dir not
being included in the cabal source distribution.

* Fix the incorrect serialization of the registry URI
  • Loading branch information
ixmatus authored Feb 12, 2018
1 parent ef9e6bd commit 19c51d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Network/Wreq/Docker/Image.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import Data.HashSet as Set
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Text.Encoding (decodeUtf8')
import NeatInterpolation
import qualified Network.Wreq as Wreq
import System.FilePath.Posix as File
import System.Terminal.Concurrent
import qualified URI.ByteString as URI

import Data.Docker.Image.Types
import Hocker.Lib
Expand All @@ -48,11 +50,16 @@ fetchImage :: HockerMeta -> IO (Either HockerException Text)
fetchImage =
runHocker $ ask >>= \HockerMeta{..} -> do
imageOutDir <- Hocker.Lib.requirePath outDir
manifest <- fetchManifest >>= checkResponseIntegrity'
manifest <- fetchManifest
configDigest <- getConfigDigest $ manifest ^. Wreq.responseBody

-- TODO: use Managed

let serializedDockerRegistry = URI.serializeURIRef' dockerRegistry
let badDecode e = throwError (HockerException (show e) Nothing Nothing)

dockerRegistryText <- either badDecode pure (decodeUtf8' serializedDockerRegistry)

-- Fetch and write the configuration json file for the image
let configFileHash = Hocker.Lib.stripHashId . Text.pack $ showSHA configDigest
imageConfig <- fetchImageConfig configDigest
Expand All @@ -65,7 +72,7 @@ fetchImage =
refLayers' = fmap Hocker.Lib.stripHashId refLayers
refLayerSet = Set.fromList refLayers'
manifestLayers = pluckLayersFrom $ manifest ^. Wreq.responseBody
(_, strippedReg) = Text.breakOnEnd "//" . Text.pack . show $ dockerRegistry
(_, strippedReg) = Text.breakOnEnd "//" dockerRegistryText
repoTags = (Text.unpack strippedReg) </> (coerce imageName)

-- Concurrently fetch layers and write to disk with a limit of three
Expand Down

0 comments on commit 19c51d0

Please sign in to comment.