{-# 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.Lightsail.Types.Container
-- 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.Lightsail.Types.Container where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types.ContainerServiceProtocol
import qualified Amazonka.Prelude as Prelude

-- | Describes the settings of a container that will be launched, or that is
-- launched, to an Amazon Lightsail container service.
--
-- /See:/ 'newContainer' smart constructor.
data Container = Container'
  { -- | The launch command for the container.
    Container -> Maybe [Text]
command :: Prelude.Maybe [Prelude.Text],
    -- | The environment variables of the container.
    Container -> Maybe (HashMap Text Text)
environment :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name of the image used for the container.
    --
    -- Container images sourced from your Lightsail container service, that are
    -- registered and stored on your service, start with a colon (@:@). For
    -- example, if your container service name is @container-service-1@, the
    -- container image label is @mystaticsite@, and you want to use the third
    -- (@3@) version of the registered container image, then you should specify
    -- @:container-service-1.mystaticsite.3@. To use the latest version of a
    -- container image, specify @latest@ instead of a version number (for
    -- example, @:container-service-1.mystaticsite.latest@). Lightsail will
    -- automatically use the highest numbered version of the registered
    -- container image.
    --
    -- Container images sourced from a public registry like Docker Hub don\'t
    -- start with a colon. For example, @nginx:latest@ or @nginx@.
    Container -> Maybe Text
image :: Prelude.Maybe Prelude.Text,
    -- | The open firewall ports of the container.
    Container -> Maybe (HashMap Text ContainerServiceProtocol)
ports :: Prelude.Maybe (Prelude.HashMap Prelude.Text ContainerServiceProtocol)
  }
  deriving (Container -> Container -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Container -> Container -> Bool
$c/= :: Container -> Container -> Bool
== :: Container -> Container -> Bool
$c== :: Container -> Container -> Bool
Prelude.Eq, ReadPrec [Container]
ReadPrec Container
Int -> ReadS Container
ReadS [Container]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Container]
$creadListPrec :: ReadPrec [Container]
readPrec :: ReadPrec Container
$creadPrec :: ReadPrec Container
readList :: ReadS [Container]
$creadList :: ReadS [Container]
readsPrec :: Int -> ReadS Container
$creadsPrec :: Int -> ReadS Container
Prelude.Read, Int -> Container -> ShowS
[Container] -> ShowS
Container -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Container] -> ShowS
$cshowList :: [Container] -> ShowS
show :: Container -> String
$cshow :: Container -> String
showsPrec :: Int -> Container -> ShowS
$cshowsPrec :: Int -> Container -> ShowS
Prelude.Show, forall x. Rep Container x -> Container
forall x. Container -> Rep Container x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Container x -> Container
$cfrom :: forall x. Container -> Rep Container x
Prelude.Generic)

-- |
-- Create a value of 'Container' 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:
--
-- 'command', 'container_command' - The launch command for the container.
--
-- 'environment', 'container_environment' - The environment variables of the container.
--
-- 'image', 'container_image' - The name of the image used for the container.
--
-- Container images sourced from your Lightsail container service, that are
-- registered and stored on your service, start with a colon (@:@). For
-- example, if your container service name is @container-service-1@, the
-- container image label is @mystaticsite@, and you want to use the third
-- (@3@) version of the registered container image, then you should specify
-- @:container-service-1.mystaticsite.3@. To use the latest version of a
-- container image, specify @latest@ instead of a version number (for
-- example, @:container-service-1.mystaticsite.latest@). Lightsail will
-- automatically use the highest numbered version of the registered
-- container image.
--
-- Container images sourced from a public registry like Docker Hub don\'t
-- start with a colon. For example, @nginx:latest@ or @nginx@.
--
-- 'ports', 'container_ports' - The open firewall ports of the container.
newContainer ::
  Container
newContainer :: Container
newContainer =
  Container'
    { $sel:command:Container' :: Maybe [Text]
command = forall a. Maybe a
Prelude.Nothing,
      $sel:environment:Container' :: Maybe (HashMap Text Text)
environment = forall a. Maybe a
Prelude.Nothing,
      $sel:image:Container' :: Maybe Text
image = forall a. Maybe a
Prelude.Nothing,
      $sel:ports:Container' :: Maybe (HashMap Text ContainerServiceProtocol)
ports = forall a. Maybe a
Prelude.Nothing
    }

-- | The launch command for the container.
container_command :: Lens.Lens' Container (Prelude.Maybe [Prelude.Text])
container_command :: Lens' Container (Maybe [Text])
container_command = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe [Text]
command :: Maybe [Text]
$sel:command:Container' :: Container -> Maybe [Text]
command} -> Maybe [Text]
command) (\s :: Container
s@Container' {} Maybe [Text]
a -> Container
s {$sel:command:Container' :: Maybe [Text]
command = Maybe [Text]
a} :: Container) 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 environment variables of the container.
container_environment :: Lens.Lens' Container (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
container_environment :: Lens' Container (Maybe (HashMap Text Text))
container_environment = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe (HashMap Text Text)
environment :: Maybe (HashMap Text Text)
$sel:environment:Container' :: Container -> Maybe (HashMap Text Text)
environment} -> Maybe (HashMap Text Text)
environment) (\s :: Container
s@Container' {} Maybe (HashMap Text Text)
a -> Container
s {$sel:environment:Container' :: Maybe (HashMap Text Text)
environment = Maybe (HashMap Text Text)
a} :: Container) 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 name of the image used for the container.
--
-- Container images sourced from your Lightsail container service, that are
-- registered and stored on your service, start with a colon (@:@). For
-- example, if your container service name is @container-service-1@, the
-- container image label is @mystaticsite@, and you want to use the third
-- (@3@) version of the registered container image, then you should specify
-- @:container-service-1.mystaticsite.3@. To use the latest version of a
-- container image, specify @latest@ instead of a version number (for
-- example, @:container-service-1.mystaticsite.latest@). Lightsail will
-- automatically use the highest numbered version of the registered
-- container image.
--
-- Container images sourced from a public registry like Docker Hub don\'t
-- start with a colon. For example, @nginx:latest@ or @nginx@.
container_image :: Lens.Lens' Container (Prelude.Maybe Prelude.Text)
container_image :: Lens' Container (Maybe Text)
container_image = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe Text
image :: Maybe Text
$sel:image:Container' :: Container -> Maybe Text
image} -> Maybe Text
image) (\s :: Container
s@Container' {} Maybe Text
a -> Container
s {$sel:image:Container' :: Maybe Text
image = Maybe Text
a} :: Container)

-- | The open firewall ports of the container.
container_ports :: Lens.Lens' Container (Prelude.Maybe (Prelude.HashMap Prelude.Text ContainerServiceProtocol))
container_ports :: Lens' Container (Maybe (HashMap Text ContainerServiceProtocol))
container_ports = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Container' {Maybe (HashMap Text ContainerServiceProtocol)
ports :: Maybe (HashMap Text ContainerServiceProtocol)
$sel:ports:Container' :: Container -> Maybe (HashMap Text ContainerServiceProtocol)
ports} -> Maybe (HashMap Text ContainerServiceProtocol)
ports) (\s :: Container
s@Container' {} Maybe (HashMap Text ContainerServiceProtocol)
a -> Container
s {$sel:ports:Container' :: Maybe (HashMap Text ContainerServiceProtocol)
ports = Maybe (HashMap Text ContainerServiceProtocol)
a} :: Container) 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

instance Data.FromJSON Container where
  parseJSON :: Value -> Parser Container
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Container"
      ( \Object
x ->
          Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe (HashMap Text ContainerServiceProtocol)
-> Container
Container'
            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
"command" 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 (Maybe a)
Data..:? Key
"environment" 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 (Maybe a)
Data..:? Key
"image")
            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
"ports" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Container where
  hashWithSalt :: Int -> Container -> Int
hashWithSalt Int
_salt Container' {Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text ContainerServiceProtocol)
ports :: Maybe (HashMap Text ContainerServiceProtocol)
image :: Maybe Text
environment :: Maybe (HashMap Text Text)
command :: Maybe [Text]
$sel:ports:Container' :: Container -> Maybe (HashMap Text ContainerServiceProtocol)
$sel:image:Container' :: Container -> Maybe Text
$sel:environment:Container' :: Container -> Maybe (HashMap Text Text)
$sel:command:Container' :: Container -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
command
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
environment
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
image
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text ContainerServiceProtocol)
ports

instance Prelude.NFData Container where
  rnf :: Container -> ()
rnf Container' {Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text ContainerServiceProtocol)
ports :: Maybe (HashMap Text ContainerServiceProtocol)
image :: Maybe Text
environment :: Maybe (HashMap Text Text)
command :: Maybe [Text]
$sel:ports:Container' :: Container -> Maybe (HashMap Text ContainerServiceProtocol)
$sel:image:Container' :: Container -> Maybe Text
$sel:environment:Container' :: Container -> Maybe (HashMap Text Text)
$sel:command:Container' :: Container -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
command
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
environment
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
image
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text ContainerServiceProtocol)
ports

instance Data.ToJSON Container where
  toJSON :: Container -> Value
toJSON Container' {Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text ContainerServiceProtocol)
ports :: Maybe (HashMap Text ContainerServiceProtocol)
image :: Maybe Text
environment :: Maybe (HashMap Text Text)
command :: Maybe [Text]
$sel:ports:Container' :: Container -> Maybe (HashMap Text ContainerServiceProtocol)
$sel:image:Container' :: Container -> Maybe Text
$sel:environment:Container' :: Container -> Maybe (HashMap Text Text)
$sel:command:Container' :: Container -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"command" 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]
command,
            (Key
"environment" 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 (HashMap Text Text)
environment,
            (Key
"image" 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
image,
            (Key
"ports" 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 (HashMap Text ContainerServiceProtocol)
ports
          ]
      )