Skip to content

Commit 164fd15

Browse files
authored
Merge pull request #6 from perkss/adding-further-commands
Adding further commands
2 parents 7b444e7 + ba9c1a1 commit 164fd15

54 files changed

Lines changed: 2164 additions & 59 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build_cmake.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,41 @@ env:
1111

1212
jobs:
1313
macos-native-x86_64:
14-
name: 'macOS 13'
14+
name: 'macos-15-intel'
1515
# Use latest image, but hardcode version to avoid silent upgrades (and breaks).
1616
# See: https://github.com/actions/runner-images#available-images.
17-
runs-on: macos-13 # Use M1 once available https://github.com/github/roadmap/issues/528
17+
runs-on: macos-15-intel # Use M1 once available https://github.com/github/roadmap/issues/528
1818
steps:
1919
- name: Checkout
2020
uses: actions/checkout@v4
2121
- name: Clang version
2222
run: clang --version
2323
- name: cmake version
2424
run: cmake -version
25-
- name: install docker
26-
run: |
27-
brew install colima docker
28-
colima start
29-
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
30-
- name: docker version
31-
run: docker ps
32-
25+
- name: Checkout submodules
26+
run: git submodule update --init --recursive
3327
- name: Install Homebrew packages
3428
run: |
35-
brew install cmake boost spdlog nlohmann-json llvm curl
29+
# Install required build-time packages but let the setup-docker action manage Colima/Docker
30+
brew install cmake boost spdlog nlohmann-json llvm curl ninja
3631
ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
3732
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
3833
ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"
34+
- name: Setup Docker on macOS
35+
id: setup-docker
36+
uses: douglascamata/setup-docker-macos-action@v1
37+
with:
38+
# Pass Colima startup options (CPU and memory) via the additional options input
39+
colima-additional-options: '--cpu 4 --memory 8'
40+
colima-network-address: false
41+
- name: Log Docker and Colima versions
42+
run: |
43+
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
44+
echo "Colima version: ${{ steps.setup-docker.outputs.colima-version }}"
45+
echo "Docker client version: ${{ steps.setup-docker.outputs.docker-client-version }}"
46+
- name: Verify Docker
47+
run: |
48+
docker ps || { echo "Docker not responding, waiting..."; sleep 10; docker ps; }
3949
- name: Build CMAKE directory
4050
run: |
4151
CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -S . -B build
@@ -46,13 +56,13 @@ jobs:
4656
name: "Ubuntu"
4757
runs-on: ubuntu-latest
4858
steps:
49-
- uses: actions/checkout@v2
59+
- uses: actions/checkout@v4
5060
- name: Checkout submodules
5161
run: git submodule update --init --recursive
5262
- name: Create build directory and run CMake
5363
run: |
5464
sudo apt-get -y update
55-
sudo apt-get install build-essential cmake g++-10 gcc-10 libgtest-dev make libssl-dev python3-dev autotools-dev libicu-dev libbz2-dev libboost-all-dev libspdlog-dev nlohmann-json3-dev llvm curl libcurl4-openssl-dev
65+
sudo apt-get install -y build-essential cmake g++-10 gcc-10 libgtest-dev make libssl-dev python3-dev autotools-dev libicu-dev libbz2-dev libboost-all-dev libspdlog-dev nlohmann-json3-dev llvm curl libcurl4-openssl-dev ninja-build
5666
ls
5767
g++ --version
5868
CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -S . -B build

include/attach_container_cmd.hh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef ATTACH_CONTAINER_CMD_HPP
2+
#define ATTACH_CONTAINER_CMD_HPP
3+
4+
#include <memory>
5+
#include <nlohmann/json.hpp>
6+
7+
#include "abstr_sync_docker_cmd_exec.hh"
8+
#include "synch_docker_cmd.hh"
9+
10+
namespace dockercpp::command {
11+
12+
class AttachContainerCmd : public SynchDockerCmd<bool>,
13+
public std::enable_shared_from_this<AttachContainerCmd> {
14+
public:
15+
virtual std::string getContainerId() = 0;
16+
};
17+
18+
namespace attachcontainer {
19+
class Exec : public exec::DockerCmdSyncExec<AttachContainerCmd, bool> {
20+
public:
21+
~Exec() {}
22+
};
23+
} // namespace attachcontainer
24+
25+
class AttachContainerCmdImpl : public AttachContainerCmd,
26+
public AbstrDockerCmd<AttachContainerCmd, bool> {
27+
public:
28+
explicit AttachContainerCmdImpl(std::unique_ptr<attachcontainer::Exec> exec,
29+
const std::string& containerId);
30+
31+
bool exec() override;
32+
33+
void close() override {}
34+
35+
std::string getContainerId() override;
36+
37+
~AttachContainerCmdImpl() {}
38+
39+
private:
40+
std::string m_containerId;
41+
};
42+
43+
} // namespace dockercpp::command
44+
#endif /* ATTACH_CONTAINER_CMD_HPP */

include/commit_container_cmd.hh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef COMMIT_CONTAINER_CMD_HPP
2+
#define COMMIT_CONTAINER_CMD_HPP
3+
4+
#include <memory>
5+
#include <nlohmann/json.hpp>
6+
7+
#include "abstr_sync_docker_cmd_exec.hh"
8+
#include "synch_docker_cmd.hh"
9+
10+
namespace dockercpp::command {
11+
12+
class CommitContainerCmd : public SynchDockerCmd<std::string>,
13+
public std::enable_shared_from_this<CommitContainerCmd> {
14+
public:
15+
virtual std::string getContainerId() = 0;
16+
virtual std::string getRepository() = 0;
17+
};
18+
19+
namespace commitcontainer {
20+
class Exec : public exec::DockerCmdSyncExec<CommitContainerCmd, std::string> {
21+
public:
22+
~Exec() {}
23+
};
24+
} // namespace commitcontainer
25+
26+
class CommitContainerCmdImpl : public CommitContainerCmd,
27+
public AbstrDockerCmd<CommitContainerCmd, std::string> {
28+
public:
29+
explicit CommitContainerCmdImpl(std::unique_ptr<commitcontainer::Exec> exec,
30+
const std::string& containerId,
31+
const std::string& repository);
32+
33+
std::string exec() override;
34+
35+
void close() override {}
36+
37+
std::string getContainerId() override;
38+
std::string getRepository() override;
39+
40+
~CommitContainerCmdImpl() {}
41+
42+
private:
43+
std::string m_containerId;
44+
std::string m_repository;
45+
};
46+
47+
} // namespace dockercpp::command
48+
#endif /* COMMIT_CONTAINER_CMD_HPP */

include/create_container_cmd.hh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define INCLUDE_CREATE_CONTAINER_CMD_HPP
33

44
#include <memory>
5+
#include <map>
56
#include <nlohmann/json.hpp>
67

78
#include "abstr_sync_docker_cmd_exec.hh"
@@ -15,6 +16,11 @@ struct CreateContainerRequest {
1516
std::string hostName;
1617
std::string name;
1718
std::vector<std::string> cmd;
19+
std::map<std::string, std::string> labels;
20+
};
21+
22+
struct HostConfig {
23+
std::string hostName;
1824
};
1925

2026
class CreateContainerCmd
@@ -29,6 +35,10 @@ class CreateContainerCmd
2935

3036
CreateContainerCmd& withCmd(const std::vector<std::string>& cmd);
3137

38+
CreateContainerCmd& withLabels(const std::map<std::string, std::string>& labels);
39+
40+
CreateContainerCmd& withLabel(const std::string& key, const std::string& value);
41+
3242
CreateContainerRequest getRequest() { return request; }
3343

3444
~CreateContainerCmd() override = default;

include/docker_client.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define DOCKER_CLIENT_H
33

44
#include "create_container_cmd.hh"
5+
#include "events_cmd.hh"
56
#include "info_cmd.hh"
67
#include "ping_cmd.hh"
78
#include "pull_image_cmd.hh"
@@ -43,6 +44,7 @@ class DockerClient {
4344

4445
std::shared_ptr<command::RemoveContainerCmd> removeContainerCmd(std::string id);
4546

47+
std::shared_ptr<command::EventsCmd> eventsCmd();
4648
};
4749

4850
}; // namespace dockercpp

include/docker_exception.hh

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,63 @@
11
#ifndef DOCKER_EXCEPTION_H
22
#define DOCKER_EXCEPTION_H
33

4-
class DockerException {
4+
#include <exception>
5+
#include <string>
56

7+
namespace dockercpp {
8+
9+
class DockerException : public std::runtime_error {
10+
public:
11+
DockerException(const std::string& message)
12+
: std::runtime_error(message), statusCode_(0) {}
13+
14+
DockerException(const std::string& message, int statusCode)
15+
: std::runtime_error(message), statusCode_(statusCode) {}
16+
17+
DockerException(const std::string& message, int statusCode, const std::string& responseBody)
18+
: std::runtime_error(message),
19+
statusCode_(statusCode),
20+
responseBody_(responseBody) {}
21+
22+
int getStatusCode() const { return statusCode_; }
23+
const std::string& getResponseBody() const { return responseBody_; }
24+
25+
private:
26+
int statusCode_;
27+
std::string responseBody_;
28+
};
29+
30+
// Specific Docker exceptions
31+
class DockerClientException : public DockerException {
32+
public:
33+
explicit DockerClientException(const std::string& message)
34+
: DockerException(message) {}
35+
};
36+
37+
class NotModifiedException : public DockerException {
38+
public:
39+
NotModifiedException(const std::string& message)
40+
: DockerException(message, 304) {}
641
};
742

43+
class NotFoundException : public DockerException {
44+
public:
45+
NotFoundException(const std::string& message)
46+
: DockerException(message, 404) {}
47+
};
48+
49+
class ConflictException : public DockerException {
50+
public:
51+
ConflictException(const std::string& message)
52+
: DockerException(message, 409) {}
53+
};
54+
55+
class InternalServerErrorException : public DockerException {
56+
public:
57+
InternalServerErrorException(const std::string& message)
58+
: DockerException(message, 500) {}
59+
};
60+
61+
} // namespace dockercpp
62+
863
#endif

0 commit comments

Comments
 (0)