master
h 84 lines 4.13 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 ImageService.h
8
9 Abstract:
10
11 This file contains the ImageService definition
12
13 --*/
14 #pragma once
15
16 #include "SessionModel.h"
17 #include "ImageModel.h"
18 #include "Terminal.h"
19 #include <map>
20 #include <optional>
21 #include <vector>
22 #include <wslc_schema.h>
23
24 namespace wsl::windows::wslc::services {
25
26 struct BuildSecret
27 {
28 std::wstring Id; // value for docker's --secret id= field
29 // For file (src=) secrets: the resolved absolute host path. The service mounts the file's parent
30 // directory into the build VM read-only and references the file in place, so the bytes are never
31 // copied off their original (possibly EFS-encrypted) location. Empty for env/in-memory secrets.
32 std::wstring SourcePath;
33 // For env/in-memory secrets: the raw secret bytes (may contain NULs), materialized into a host-side
34 // file mounted read-only into the VM during the build. Empty for file secrets.
35 std::vector<BYTE> Value;
36 };
37
38 // Parsed docker-style --output spec (buildx exporter). Type/Dest are the resolved exporter type and
39 // destination; any remaining key=value attributes (name, push, compression, ...) are carried verbatim.
40 struct BuildOutput
41 {
42 std::wstring Type; // resolved exporter type (e.g. L"local", L"tar", ...)
43 std::wstring Dest; // destination path; L"-" means stdout; empty when not applicable
44 std::map<std::wstring, std::wstring> Attributes; // remaining key=value attributes
45 };
46
47 class ImageService
48 {
49 public:
50 static void Build(
51 wsl::windows::wslc::models::Session& session,
52 const std::wstring& contextPath,
53 const std::vector<std::wstring>& tags,
54 const std::vector<std::wstring>& buildArgs,
55 const std::vector<std::wstring>& labels,
56 const std::vector<BuildSecret>& secrets,
57 const std::wstring& dockerfilePath,
58 const std::wstring& target,
59 const std::optional<BuildOutput>& output,
60 const std::optional<std::wstring>& iidFilePath,
61 WSLCBuildImageFlags flags,
62 IProgressCallback* callback,
63 HANDLE cancelEvent = nullptr);
64
65 // Container counts are only gathered when requested: it costs an extra query, and the service
66 // computes it alongside the image list so the two are consistent.
67 static std::vector<wsl::windows::wslc::models::ImageInformation> List(
68 wsl::windows::wslc::models::Session& session,
69 const std::vector<std::pair<std::string, std::string>>& filters = {},
70 bool containerCounts = false);
71 static void Load(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::wstring& input, IImageLoadCallback* callback = nullptr);
72 static std::string Import(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::wstring& input, const std::string& imageName);
73 static std::vector<wsl::windows::wslc::models::DeletedImageEntry> Delete(
74 wsl::windows::wslc::models::Session& session, const std::string& image, bool force, bool noPrune);
75 static wsl::windows::common::wslc_schema::InspectImage Inspect(wsl::windows::wslc::models::Session& session, const std::string& image);
76 static void Pull(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback);
77 static void Push(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback);
78 static void Save(wsl::windows::wslc::models::Session& session, const std::vector<std::string>& images, const std::wstring& output, HANDLE cancelEvent = nullptr);
79 static void Save(wsl::windows::wslc::models::Session& session, const std::vector<std::string>& images, HANDLE outputHandle, HANDLE cancelEvent = nullptr);
80 static void Tag(wsl::windows::wslc::models::Session& session, const std::string& sourceImage, const std::string& targetImage);
81 static wsl::windows::wslc::models::PruneImagesResult Prune(
82 wsl::windows::wslc::models::Session& session, bool all, const std::vector<std::pair<std::string, std::string>>& filters = {});
83 };
84 } // namespace wsl::windows::wslc::services