{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodeBuild.Types.ProjectCache
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodeBuild.Types.ProjectCache where

import Amazonka.CodeBuild.Types.CacheMode
import Amazonka.CodeBuild.Types.CacheType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Information about the cache for the build project.
--
-- /See:/ 'newProjectCache' smart constructor.
data ProjectCache = ProjectCache'
  { -- | Information about the cache location:
    --
    -- -   @NO_CACHE@ or @LOCAL@: This value is ignored.
    --
    -- -   @S3@: This is the S3 bucket name\/prefix.
    ProjectCache -> Maybe Text
location :: Prelude.Maybe Prelude.Text,
    -- | An array of strings that specify the local cache modes. You can use one
    -- or more local cache modes at the same time. This is only used for
    -- @LOCAL@ cache types.
    --
    -- Possible values are:
    --
    -- [LOCAL_SOURCE_CACHE]
    --     Caches Git metadata for primary and secondary sources. After the
    --     cache is created, subsequent builds pull only the change between
    --     commits. This mode is a good choice for projects with a clean
    --     working directory and a source that is a large Git repository. If
    --     you choose this option and your project does not use a Git
    --     repository (GitHub, GitHub Enterprise, or Bitbucket), the option is
    --     ignored.
    --
    -- [LOCAL_DOCKER_LAYER_CACHE]
    --     Caches existing Docker layers. This mode is a good choice for
    --     projects that build or pull large Docker images. It can prevent the
    --     performance issues caused by pulling large Docker images down from
    --     the network.
    --
    --     -   You can use a Docker layer cache in the Linux environment only.
    --
    --     -   The @privileged@ flag must be set so that your project has the
    --         required Docker permissions.
    --
    --     -   You should consider the security implications before you use a
    --         Docker layer cache.
    --
    -- [LOCAL_CUSTOM_CACHE]
    --     Caches directories you specify in the buildspec file. This mode is a
    --     good choice if your build scenario is not suited to one of the other
    --     three local cache modes. If you use a custom cache:
    --
    --     -   Only directories can be specified for caching. You cannot
    --         specify individual files.
    --
    --     -   Symlinks are used to reference cached directories.
    --
    --     -   Cached directories are linked to your build before it downloads
    --         its project sources. Cached items are overridden if a source
    --         item has the same name. Directories are specified using cache
    --         paths in the buildspec file.
    ProjectCache -> Maybe [CacheMode]
modes :: Prelude.Maybe [CacheMode],
    -- | The type of cache used by the build project. Valid values include:
    --
    -- -   @NO_CACHE@: The build project does not use any cache.
    --
    -- -   @S3@: The build project reads and writes from and to S3.
    --
    -- -   @LOCAL@: The build project stores a cache locally on a build host
    --     that is only available to that build host.
    ProjectCache -> CacheType
type' :: CacheType
  }
  deriving (ProjectCache -> ProjectCache -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProjectCache -> ProjectCache -> Bool
$c/= :: ProjectCache -> ProjectCache -> Bool
== :: ProjectCache -> ProjectCache -> Bool
$c== :: ProjectCache -> ProjectCache -> Bool
Prelude.Eq, ReadPrec [ProjectCache]
ReadPrec ProjectCache
Int -> ReadS ProjectCache
ReadS [ProjectCache]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProjectCache]
$creadListPrec :: ReadPrec [ProjectCache]
readPrec :: ReadPrec ProjectCache
$creadPrec :: ReadPrec ProjectCache
readList :: ReadS [ProjectCache]
$creadList :: ReadS [ProjectCache]
readsPrec :: Int -> ReadS ProjectCache
$creadsPrec :: Int -> ReadS ProjectCache
Prelude.Read, Int -> ProjectCache -> ShowS
[ProjectCache] -> ShowS
ProjectCache -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProjectCache] -> ShowS
$cshowList :: [ProjectCache] -> ShowS
show :: ProjectCache -> String
$cshow :: ProjectCache -> String
showsPrec :: Int -> ProjectCache -> ShowS
$cshowsPrec :: Int -> ProjectCache -> ShowS
Prelude.Show, forall x. Rep ProjectCache x -> ProjectCache
forall x. ProjectCache -> Rep ProjectCache x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProjectCache x -> ProjectCache
$cfrom :: forall x. ProjectCache -> Rep ProjectCache x
Prelude.Generic)

-- |
-- Create a value of 'ProjectCache' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'location', 'projectCache_location' - Information about the cache location:
--
-- -   @NO_CACHE@ or @LOCAL@: This value is ignored.
--
-- -   @S3@: This is the S3 bucket name\/prefix.
--
-- 'modes', 'projectCache_modes' - An array of strings that specify the local cache modes. You can use one
-- or more local cache modes at the same time. This is only used for
-- @LOCAL@ cache types.
--
-- Possible values are:
--
-- [LOCAL_SOURCE_CACHE]
--     Caches Git metadata for primary and secondary sources. After the
--     cache is created, subsequent builds pull only the change between
--     commits. This mode is a good choice for projects with a clean
--     working directory and a source that is a large Git repository. If
--     you choose this option and your project does not use a Git
--     repository (GitHub, GitHub Enterprise, or Bitbucket), the option is
--     ignored.
--
-- [LOCAL_DOCKER_LAYER_CACHE]
--     Caches existing Docker layers. This mode is a good choice for
--     projects that build or pull large Docker images. It can prevent the
--     performance issues caused by pulling large Docker images down from
--     the network.
--
--     -   You can use a Docker layer cache in the Linux environment only.
--
--     -   The @privileged@ flag must be set so that your project has the
--         required Docker permissions.
--
--     -   You should consider the security implications before you use a
--         Docker layer cache.
--
-- [LOCAL_CUSTOM_CACHE]
--     Caches directories you specify in the buildspec file. This mode is a
--     good choice if your build scenario is not suited to one of the other
--     three local cache modes. If you use a custom cache:
--
--     -   Only directories can be specified for caching. You cannot
--         specify individual files.
--
--     -   Symlinks are used to reference cached directories.
--
--     -   Cached directories are linked to your build before it downloads
--         its project sources. Cached items are overridden if a source
--         item has the same name. Directories are specified using cache
--         paths in the buildspec file.
--
-- 'type'', 'projectCache_type' - The type of cache used by the build project. Valid values include:
--
-- -   @NO_CACHE@: The build project does not use any cache.
--
-- -   @S3@: The build project reads and writes from and to S3.
--
-- -   @LOCAL@: The build project stores a cache locally on a build host
--     that is only available to that build host.
newProjectCache ::
  -- | 'type''
  CacheType ->
  ProjectCache
newProjectCache :: CacheType -> ProjectCache
newProjectCache CacheType
pType_ =
  ProjectCache'
    { $sel:location:ProjectCache' :: Maybe Text
location = forall a. Maybe a
Prelude.Nothing,
      $sel:modes:ProjectCache' :: Maybe [CacheMode]
modes = forall a. Maybe a
Prelude.Nothing,
      $sel:type':ProjectCache' :: CacheType
type' = CacheType
pType_
    }

-- | Information about the cache location:
--
-- -   @NO_CACHE@ or @LOCAL@: This value is ignored.
--
-- -   @S3@: This is the S3 bucket name\/prefix.
projectCache_location :: Lens.Lens' ProjectCache (Prelude.Maybe Prelude.Text)
projectCache_location :: Lens' ProjectCache (Maybe Text)
projectCache_location = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectCache' {Maybe Text
location :: Maybe Text
$sel:location:ProjectCache' :: ProjectCache -> Maybe Text
location} -> Maybe Text
location) (\s :: ProjectCache
s@ProjectCache' {} Maybe Text
a -> ProjectCache
s {$sel:location:ProjectCache' :: Maybe Text
location = Maybe Text
a} :: ProjectCache)

-- | An array of strings that specify the local cache modes. You can use one
-- or more local cache modes at the same time. This is only used for
-- @LOCAL@ cache types.
--
-- Possible values are:
--
-- [LOCAL_SOURCE_CACHE]
--     Caches Git metadata for primary and secondary sources. After the
--     cache is created, subsequent builds pull only the change between
--     commits. This mode is a good choice for projects with a clean
--     working directory and a source that is a large Git repository. If
--     you choose this option and your project does not use a Git
--     repository (GitHub, GitHub Enterprise, or Bitbucket), the option is
--     ignored.
--
-- [LOCAL_DOCKER_LAYER_CACHE]
--     Caches existing Docker layers. This mode is a good choice for
--     projects that build or pull large Docker images. It can prevent the
--     performance issues caused by pulling large Docker images down from
--     the network.
--
--     -   You can use a Docker layer cache in the Linux environment only.
--
--     -   The @privileged@ flag must be set so that your project has the
--         required Docker permissions.
--
--     -   You should consider the security implications before you use a
--         Docker layer cache.
--
-- [LOCAL_CUSTOM_CACHE]
--     Caches directories you specify in the buildspec file. This mode is a
--     good choice if your build scenario is not suited to one of the other
--     three local cache modes. If you use a custom cache:
--
--     -   Only directories can be specified for caching. You cannot
--         specify individual files.
--
--     -   Symlinks are used to reference cached directories.
--
--     -   Cached directories are linked to your build before it downloads
--         its project sources. Cached items are overridden if a source
--         item has the same name. Directories are specified using cache
--         paths in the buildspec file.
projectCache_modes :: Lens.Lens' ProjectCache (Prelude.Maybe [CacheMode])
projectCache_modes :: Lens' ProjectCache (Maybe [CacheMode])
projectCache_modes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectCache' {Maybe [CacheMode]
modes :: Maybe [CacheMode]
$sel:modes:ProjectCache' :: ProjectCache -> Maybe [CacheMode]
modes} -> Maybe [CacheMode]
modes) (\s :: ProjectCache
s@ProjectCache' {} Maybe [CacheMode]
a -> ProjectCache
s {$sel:modes:ProjectCache' :: Maybe [CacheMode]
modes = Maybe [CacheMode]
a} :: ProjectCache) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The type of cache used by the build project. Valid values include:
--
-- -   @NO_CACHE@: The build project does not use any cache.
--
-- -   @S3@: The build project reads and writes from and to S3.
--
-- -   @LOCAL@: The build project stores a cache locally on a build host
--     that is only available to that build host.
projectCache_type :: Lens.Lens' ProjectCache CacheType
projectCache_type :: Lens' ProjectCache CacheType
projectCache_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectCache' {CacheType
type' :: CacheType
$sel:type':ProjectCache' :: ProjectCache -> CacheType
type'} -> CacheType
type') (\s :: ProjectCache
s@ProjectCache' {} CacheType
a -> ProjectCache
s {$sel:type':ProjectCache' :: CacheType
type' = CacheType
a} :: ProjectCache)

instance Data.FromJSON ProjectCache where
  parseJSON :: Value -> Parser ProjectCache
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ProjectCache"
      ( \Object
x ->
          Maybe Text -> Maybe [CacheMode] -> CacheType -> ProjectCache
ProjectCache'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"location")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"modes" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"type")
      )

instance Prelude.Hashable ProjectCache where
  hashWithSalt :: Int -> ProjectCache -> Int
hashWithSalt Int
_salt ProjectCache' {Maybe [CacheMode]
Maybe Text
CacheType
type' :: CacheType
modes :: Maybe [CacheMode]
location :: Maybe Text
$sel:type':ProjectCache' :: ProjectCache -> CacheType
$sel:modes:ProjectCache' :: ProjectCache -> Maybe [CacheMode]
$sel:location:ProjectCache' :: ProjectCache -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
location
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [CacheMode]
modes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CacheType
type'

instance Prelude.NFData ProjectCache where
  rnf :: ProjectCache -> ()
rnf ProjectCache' {Maybe [CacheMode]
Maybe Text
CacheType
type' :: CacheType
modes :: Maybe [CacheMode]
location :: Maybe Text
$sel:type':ProjectCache' :: ProjectCache -> CacheType
$sel:modes:ProjectCache' :: ProjectCache -> Maybe [CacheMode]
$sel:location:ProjectCache' :: ProjectCache -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
location
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [CacheMode]
modes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf CacheType
type'

instance Data.ToJSON ProjectCache where
  toJSON :: ProjectCache -> Value
toJSON ProjectCache' {Maybe [CacheMode]
Maybe Text
CacheType
type' :: CacheType
modes :: Maybe [CacheMode]
location :: Maybe Text
$sel:type':ProjectCache' :: ProjectCache -> CacheType
$sel:modes:ProjectCache' :: ProjectCache -> Maybe [CacheMode]
$sel:location:ProjectCache' :: ProjectCache -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"location" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
location,
            (Key
"modes" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [CacheMode]
modes,
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= CacheType
type')
          ]
      )