Exemplo n.º 1
0
        /// <summary>
        /// Pulls the image from the remote repository if it does not exist locally
        /// </summary>
        /// <inheritdoc />
        public override async Task <string> Resolve(CancellationToken ct = default)
        {
            if (ct.IsCancellationRequested)
            {
                return(null);
            }

            if (await CheckIfImageExists(ct))
            {
                return(ImageId);
            }

            // we must only pull an image once
            // the API allows pulling the same image in parallel but suffers from race conditions that produces
            // unpredictable results or errors
            await ImagePullLocks.Get(ImageName).WaitAsync(ct);

            try
            {
                if (!await CheckIfImageExists(ct))
                {
                    await PullImage(ct);
                }
            }
            finally
            {
                ImagePullLocks.Get(ImageName).Release();
            }

            return(ImageId);
        }
        /// <inheritdoc />
        public async Task <string> Resolve(CancellationToken ct = default)
        {
            if (ct.IsCancellationRequested)
            {
                return(null);
            }

            if (await CheckIfNetworkExists(ct))
            {
                return(NetworkId);
            }

            // we must only create a single network name once
            // the API allows creating multiple networks with the same name
            // and when this name is referenced in a container, the command will fail complaining
            // that there are more than 1 networks that matches the given name
            await NetworkCreateLocks.Get(NetworkName).WaitAsync(ct);

            try
            {
                if (!await CheckIfNetworkExists(ct))
                {
                    await CreateNetwork(ct);
                }
            }
            finally
            {
                NetworkCreateLocks.Get(NetworkName).Release();
            }

            return(NetworkId);
        }