Skip to content

Commit

Permalink
Initial container registry login support (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
aptakhin authored Mar 29, 2024
1 parent 54e0c62 commit 33697cd
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 32 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
base64 = "0.22.0"
clap = { version = "4.5.3", features = ["derive"] }
env_logger = "0.11.3"
log = "0.4.21"
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ doc::
docw::
./cargo watch -x doc --no-deps

l01::
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker login --config tests/01_trivial-backend-no-storage/opday.toml -f ./secrets/docker-config.json

a01::
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker build-push-deploy --build-arg BACKEND_TAG=0.0.4 --config tests/01_trivial-backend-no-storage/opday.toml

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This tool requires local installation of another tools and their availability in

# The idea

This tool prioritizes simplicity and imperativeness over scaling and decorativeness. It provides a simple yet flexible way to maintain basic Ops operations and automates its own infrastructure. There are plenty amount of `deploy.sh` scripts we might write manually or tools like [umputun/spot](https://github.com/umputun/spot), [Kamal](https://kamal-deploy.org/) or Ansible. Usage of some of them might be overkill, but also I don't want to force people to learn one more DSL for this obvious deployment stuff. This time might be spent on learning better new programming language, Kubernetes or speaking language :) Hence, the main features are based on `docker` and `docker compose`.
This tool prioritizes simplicity and imperativeness over scaling and decorativeness. It provides a simple yet flexible way to maintain basic Ops operations and automates its own infrastructure. There are plenty amount of `deploy.sh` scripts we might write manually or tools like [umputun/spot](https://github.com/umputun/spot), [Kamal](https://kamal-deploy.org/) or Ansible. Usage of some of them might be overkill, but also I don't want to force people to learn one more DSL for this obvious deployment stuff. Hence, the main features are based on `docker` and `docker compose`.

* Allocation of resources on virtual private and dedicated servers
* Multiple providers support (docker, databases, monitoring, S3, and other storages)
Expand All @@ -41,10 +41,14 @@ This tool prioritizes simplicity and imperativeness over scaling and decorativen

Scope of applying this tool:
* Product is not Kubernetes ready. Kubernetes for monolithic or citadel-like applications brings more complexity than solving problems in the early stages.
* Less than 100 virtual machines for service. More hosts have become an issue for straightforward push architecture.
* Less than 100 virtual machines for service. More hosts might become an issue for straightforward push architecture.
* Up to 100 daily releases
* Base-level infra with trivial sharding and replication for storage and databases. Everything above might be more suitable for custom or cloud-managed services.

# User guide

[Getting started](./src/doc/getting_started.md)

# Preparing host

For Ubuntu docker please follow: https://docs.docker.com/engine/install/ubuntu/
Expand Down Expand Up @@ -79,3 +83,5 @@ RUST_LOG=debug cargo run
# Run tests with watch on change
make testw
```

Thinking contexts history [Read-only]: https://miro.com/app/board/uXjVN3A6wi4=/
1 change: 0 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct DockerComposeFormat {
pub services: Mapping,
pub volumes: Option<Mapping>,
}

pub struct Scope {
pub hosts: Vec<String>,
pub export_path: String,
Expand Down
51 changes: 51 additions & 0 deletions src/doc/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,55 @@ opday docker build

Okay, just nginx is not so interesting to build.

And for further progress we need some remote virtual machine.

For host preparing, please follow:
* For Ubuntu: https://docs.docker.com/engine/install/ubuntu/

Let's create configuration `opday.toml` in current directory.

```bash
cat > opday.toml << EOL
[environments]
registry = "registry.digitalocean.com"
[environments.prod]
export_path = "/root/test-01"
EOL
```

## Login

Login command authentificates machines to use private container registry.

It creates or uses existing `docker-config.json`, pushes it to remote machines and run `docker login` remotely.

Some container registries like `registry.digitalocean.com` gives you to download `docker-config.json` file you can use with `-f` parameter.

```bash
opday docker login -f docker-config.json
```

For other options with username and password:

```bash
opday docker login --username REGISTRY_USERNAME --password-stdin
```

Then paste the registry password, press Enter and close input (Usually it's `Ctrl+D` in terminals).

## Build

Build images locally.

## Push

Pushes images to container registry.

## Deploy

Deploys containers on remote machines.

## Summary

For more examples please take a look into `<repo-root>/tests` folder.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ mod tests {
case::config_after_sub_sub_command_plus_build_arg(vec!["", "docker", "build", "--config", "myconfig", "--build-arg", "BACKEND_TAG=0.0.1"]),
case::build_push(vec!["", "docker", "build-push"]),
case::build_push_deploy(vec!["", "docker", "build-push-deploy"]),
case::login_username(vec!["", "docker", "login", "-u", "username"]),
case::login_username_password_stdin(vec!["", "docker", "login", "-u", "username", "--password-stdin"]),
)]
fn test_config_for_any_order(args: Vec<&str>) {
assert!(Cli::try_parse_from(args).is_ok());
Expand Down
Loading

0 comments on commit 33697cd

Please sign in to comment.