Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions .github/workflows/build_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,41 @@ env:

jobs:
macos-native-x86_64:
name: 'macOS 13'
name: 'macos-15-intel'
# Use latest image, but hardcode version to avoid silent upgrades (and breaks).
# See: https://github.com/actions/runner-images#available-images.
runs-on: macos-13 # Use M1 once available https://github.com/github/roadmap/issues/528
runs-on: macos-15-intel # Use M1 once available https://github.com/github/roadmap/issues/528
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Clang version
run: clang --version
- name: cmake version
run: cmake -version
- name: install docker
run: |
brew install colima docker
colima start
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
- name: docker version
run: docker ps

- name: Checkout submodules
run: git submodule update --init --recursive
- name: Install Homebrew packages
run: |
brew install cmake boost spdlog nlohmann-json llvm curl
# Install required build-time packages but let the setup-docker action manage Colima/Docker
brew install cmake boost spdlog nlohmann-json llvm curl ninja
ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"
- name: Setup Docker on macOS
id: setup-docker
uses: douglascamata/setup-docker-macos-action@v1
with:
# Pass Colima startup options (CPU and memory) via the additional options input
colima-additional-options: '--cpu 4 --memory 8'
colima-network-address: false
- name: Log Docker and Colima versions
run: |
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
echo "Colima version: ${{ steps.setup-docker.outputs.colima-version }}"
echo "Docker client version: ${{ steps.setup-docker.outputs.docker-client-version }}"
- name: Verify Docker
run: |
docker ps || { echo "Docker not responding, waiting..."; sleep 10; docker ps; }
- name: Build CMAKE directory
run: |
CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -S . -B build
Expand All @@ -46,13 +56,13 @@ jobs:
name: "Ubuntu"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Create build directory and run CMake
run: |
sudo apt-get -y update
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
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
ls
g++ --version
CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -S . -B build
Expand Down
44 changes: 44 additions & 0 deletions include/attach_container_cmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef ATTACH_CONTAINER_CMD_HPP
#define ATTACH_CONTAINER_CMD_HPP

#include <memory>
#include <nlohmann/json.hpp>

#include "abstr_sync_docker_cmd_exec.hh"
#include "synch_docker_cmd.hh"

namespace dockercpp::command {

class AttachContainerCmd : public SynchDockerCmd<bool>,
public std::enable_shared_from_this<AttachContainerCmd> {
public:
virtual std::string getContainerId() = 0;
};

namespace attachcontainer {
class Exec : public exec::DockerCmdSyncExec<AttachContainerCmd, bool> {
public:
~Exec() {}
};
} // namespace attachcontainer

class AttachContainerCmdImpl : public AttachContainerCmd,
public AbstrDockerCmd<AttachContainerCmd, bool> {
public:
explicit AttachContainerCmdImpl(std::unique_ptr<attachcontainer::Exec> exec,
const std::string& containerId);

bool exec() override;

void close() override {}

std::string getContainerId() override;

~AttachContainerCmdImpl() {}

private:
std::string m_containerId;
};

} // namespace dockercpp::command
#endif /* ATTACH_CONTAINER_CMD_HPP */
48 changes: 48 additions & 0 deletions include/commit_container_cmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef COMMIT_CONTAINER_CMD_HPP
#define COMMIT_CONTAINER_CMD_HPP

#include <memory>
#include <nlohmann/json.hpp>

#include "abstr_sync_docker_cmd_exec.hh"
#include "synch_docker_cmd.hh"

namespace dockercpp::command {

class CommitContainerCmd : public SynchDockerCmd<std::string>,
public std::enable_shared_from_this<CommitContainerCmd> {
public:
virtual std::string getContainerId() = 0;
virtual std::string getRepository() = 0;
};

namespace commitcontainer {
class Exec : public exec::DockerCmdSyncExec<CommitContainerCmd, std::string> {
public:
~Exec() {}
};
} // namespace commitcontainer

class CommitContainerCmdImpl : public CommitContainerCmd,
public AbstrDockerCmd<CommitContainerCmd, std::string> {
public:
explicit CommitContainerCmdImpl(std::unique_ptr<commitcontainer::Exec> exec,
const std::string& containerId,
const std::string& repository);

std::string exec() override;

void close() override {}

std::string getContainerId() override;
std::string getRepository() override;

~CommitContainerCmdImpl() {}

private:
std::string m_containerId;
std::string m_repository;
};

} // namespace dockercpp::command
#endif /* COMMIT_CONTAINER_CMD_HPP */
10 changes: 10 additions & 0 deletions include/create_container_cmd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define INCLUDE_CREATE_CONTAINER_CMD_HPP

#include <memory>
#include <map>
#include <nlohmann/json.hpp>

#include "abstr_sync_docker_cmd_exec.hh"
Expand All @@ -15,6 +16,11 @@ struct CreateContainerRequest {
std::string hostName;
std::string name;
std::vector<std::string> cmd;
std::map<std::string, std::string> labels;
};

struct HostConfig {
std::string hostName;
};

class CreateContainerCmd
Expand All @@ -29,6 +35,10 @@ class CreateContainerCmd

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

CreateContainerCmd& withLabels(const std::map<std::string, std::string>& labels);

CreateContainerCmd& withLabel(const std::string& key, const std::string& value);

CreateContainerRequest getRequest() { return request; }

~CreateContainerCmd() override = default;
Expand Down
2 changes: 2 additions & 0 deletions include/docker_client.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DOCKER_CLIENT_H

#include "create_container_cmd.hh"
#include "events_cmd.hh"
#include "info_cmd.hh"
#include "ping_cmd.hh"
#include "pull_image_cmd.hh"
Expand Down Expand Up @@ -43,6 +44,7 @@ class DockerClient {

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

std::shared_ptr<command::EventsCmd> eventsCmd();
};

}; // namespace dockercpp
Expand Down
57 changes: 56 additions & 1 deletion include/docker_exception.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,63 @@
#ifndef DOCKER_EXCEPTION_H
#define DOCKER_EXCEPTION_H

class DockerException {
#include <exception>
#include <string>

namespace dockercpp {

class DockerException : public std::runtime_error {
public:
DockerException(const std::string& message)
: std::runtime_error(message), statusCode_(0) {}

DockerException(const std::string& message, int statusCode)
: std::runtime_error(message), statusCode_(statusCode) {}

DockerException(const std::string& message, int statusCode, const std::string& responseBody)
: std::runtime_error(message),
statusCode_(statusCode),
responseBody_(responseBody) {}

int getStatusCode() const { return statusCode_; }
const std::string& getResponseBody() const { return responseBody_; }

private:
int statusCode_;
std::string responseBody_;
};

// Specific Docker exceptions
class DockerClientException : public DockerException {
public:
explicit DockerClientException(const std::string& message)
: DockerException(message) {}
};

class NotModifiedException : public DockerException {
public:
NotModifiedException(const std::string& message)
: DockerException(message, 304) {}
};

class NotFoundException : public DockerException {
public:
NotFoundException(const std::string& message)
: DockerException(message, 404) {}
};

class ConflictException : public DockerException {
public:
ConflictException(const std::string& message)
: DockerException(message, 409) {}
};

class InternalServerErrorException : public DockerException {
public:
InternalServerErrorException(const std::string& message)
: DockerException(message, 500) {}
};

} // namespace dockercpp

#endif
Loading
Loading