Skip to content

Commit

Permalink
CI test.
Browse files Browse the repository at this point in the history
  • Loading branch information
csasarak committed Sep 11, 2024
1 parent c1d30b2 commit bf3bf4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions src/Control/Carrier/ContainerRegistryApi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import Network.HTTP.Conduit qualified as HTTPConduit
import Network.HTTP.Types.Header (ResponseHeaders)
import Path (Abs, Dir, File, Path, filename, mkRelFile, toFilePath, (</>))
import Path.Internal (Path (..))
import Debug.Trace (traceShowM)

-- | A carrier to run Registry API functions in the IO monad
type ContainerRegistryApiC m = SimpleC ContainerRegistryApiF (ReaderC RegistryCtx m)
Expand Down Expand Up @@ -166,14 +167,16 @@ getImageManifest ::
m OciManifestV2
getImageManifest src = context "Getting Image Manifest" $ do
manager <- reqManager
endpoint <- manifestEndpoint src
traceShowM endpoint
resp <-
fromResponse
=<< mkRequest manager (registryCred src) (Just supportedManifestKinds)
=<< manifestEndpoint src
=<< mkRequest manager (registryCred src) (Just supportedManifestKinds) endpoint

let respBody :: ByteStringLazy.ByteString
respBody = responseBody resp

traceShowM respBody
if isManifestIndex (responseHeaders resp)
then do
manifestIndex <- fromEither $ eitherDecode respBody
Expand All @@ -182,6 +185,7 @@ getImageManifest src = context "Getting Image Manifest" $ do
let platformArch :: Text
platformArch = platformArchitecture src

traceShowM manifestIndex
logDebug . pretty $ "Looking for platform architecture: " <> platformArch
manifestDigest <-
fromMaybeText
Expand All @@ -193,7 +197,10 @@ getImageManifest src = context "Getting Image Manifest" $ do
=<< (manifestEndpoint $ src{registryContainerRepositoryReference = manifestDigest})
else do
logDebug "Retrieved single-platform image manifest."
parseOciManifest resp

res <- parseOciManifest resp
traceShowM res
pure res
where
isSupportedManifestKind :: ResponseHeaders -> Bool
isSupportedManifestKind headers =
Expand Down
14 changes: 7 additions & 7 deletions test/Container/RegistryApiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Control.Effect.Lift (Lift)
import Data.Text (Text)
import Data.Void (Void)
import Test.Effect (it', shouldBe')
import Test.Hspec (Expectation, Spec, describe, it)
import Test.Hspec (Expectation, Spec, describe, it, focus)
import Test.Hspec.Megaparsec (shouldParse)
import Text.Megaparsec (Parsec, parse)
import Text.Megaparsec.Error (ParseErrorBundle)
Expand Down Expand Up @@ -42,7 +42,7 @@ getImageConfig arch img =
<$> (getImageManifest =<< fromEitherShow (decodeStrict arch img))

spec :: Spec
spec = do
spec = focus $ do
registryApiSpec
parseAuthChallengeSpec

Expand Down Expand Up @@ -104,8 +104,8 @@ registryApiSpec =
confDigest <- getImageConfig amd64 dhImageWithDigest
confDigest `shouldBe'` dhImageDigest

it' "should get manifest for multi-platform image (chooses target platform - grafana arm)" $ do
confDigest <- getImageConfig arm grafanaMultiArgeImage
focus $ it' "should get manifest for multi-platform image (chooses target platform - grafana arm)" $ do
confDigest <- getImageConfig arm64 grafanaMultiArchImage
confDigest `shouldBe'` grafanaMultiArchImageDigest

it' "should get manifest for multi-platform images (chooses target platform - redis arm64)" $ do
Expand Down Expand Up @@ -151,12 +151,12 @@ dhImageWithDigest :: Text
dhImageWithDigest =
"amazon/aws-cli@sha256:7a27c26c2937a3d0b84171675709df1dc09aa331e86cad90f74ada6df7b59c89"

grafanaMultiArgeImage :: Text
grafanaMultiArgeImage = "grafana/grafana:8.1.7-ubuntu"
grafanaMultiArchImage :: Text
grafanaMultiArchImage = "grafana/grafana:8.1.7-ubuntu"

grafanaMultiArchImageDigest :: RepoDigest
grafanaMultiArchImageDigest =
RepoDigest "sha256:fff202f54b5922c3e42c55c45a58edd1e103bffd1f62992fce49dd55500013dd"
RepoDigest "sha256:86618e1e78e4962b5abec6cc7fabe89010ebfbbf0885cbba1aada7287457c263"

mcrRegistryImage :: Text
mcrRegistryImage = "mcr.microsoft.com/azure-cli:0.10.13"
Expand Down

0 comments on commit bf3bf4d

Please sign in to comment.