Skip to content

Commit

Permalink
feat/linux, docker artefacts, skip-dependencies flag support (#8)
Browse files Browse the repository at this point in the history
* feat(release): add build linux, docker step to gh actions

* feat(core): add 'skip-dependencies' flag support

* feat(core): produce excalidraw_data as an output stream

* fix(gh-actions): leave only input-path arg

* docs: update readme, add an option for console/file output
  • Loading branch information
etolbakov authored Jun 6, 2023
1 parent db83101 commit 060c43c
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 105 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
144 changes: 140 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ on:

env:
RUST_TOOLCHAIN: nightly-2023-05-03
BUILD_VERSION_PREFIX: v0.1.3
CARGO_PROFILE: release

permissions:
contents: write

jobs:

build-macos:
name: Build macOS binary
strategy:
Expand Down Expand Up @@ -82,12 +84,146 @@ jobs:
name: ${{ matrix.file }}.sha256sum
path: target/${{ matrix.arch }}/${{ env.CARGO_PROFILE }}/${{ matrix.file }}.sha256sum

release:
name: Release artifacts
# Release artifacts only when all the artifacts are built successfully.
needs: [build-macos]
build-linux:
name: Build linux binary
strategy:
matrix:
# The file format is excalidocker-<os>-<arch>
include:
- arch: x86_64-unknown-linux-gnu
os: ubuntu-latest
file: excalidocker-linux-amd64
continue-on-error: false
- arch: aarch64-unknown-linux-gnu
os: ubuntu-latest
file: excalidocker-linux-arm64
continue-on-error: false
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.continue-on-error }}
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Cache cargo assets
id: cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ matrix.arch }}-build-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install dependencies for linux
run: |
sudo apt-get -y update
sudo apt-get -y install libssl-dev pkg-config g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu wget
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
targets: ${{ matrix.arch }}

- name: Install latest nextest release
uses: taiki-e/install-action@nextest

- name: Output package versions
run: cargo version ; rustc --version ; gcc --version ; g++ --version

- name: Run cargo build
run: cargo build --profile ${{ env.CARGO_PROFILE }} --target ${{ matrix.arch }}

- name: Calculate checksum and rename binary
shell: bash
run: |
cd target/${{ matrix.arch }}/${{ env.CARGO_PROFILE }}
chmod +x excalidocker
tar -zcvf ${{ matrix.file }}.tgz excalidocker
echo $(shasum -a 256 ${{ matrix.file }}.tgz | cut -f1 -d' ') > ${{ matrix.file }}.sha256sum
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.file }}
path: target/${{ matrix.arch }}/${{ env.CARGO_PROFILE }}/${{ matrix.file }}.tgz

- name: Upload checksum of artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.file }}.sha256sum
path: target/${{ matrix.arch }}/${{ env.CARGO_PROFILE }}/${{ matrix.file }}.sha256sum

docker:
name: Build docker image
needs: [build-linux, build-macos]
# needs: [build-linux]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Login to Dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Configure tag
shell: bash
run: |
buildTime=`date "+%Y%m%d"`
SCHEDULED_BUILD_VERSION=${{ env.BUILD_VERSION_PREFIX }}-$buildTime
echo "IMAGE_TAG=${SCHEDULED_BUILD_VERSION:1}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up buildx
uses: docker/setup-buildx-action@v2

- name: Download amd64 binary
uses: actions/download-artifact@v3
with:
name: excalidocker-linux-amd64
path: amd64

- name: Unzip the amd64 artifacts
run: |
tar xvf amd64/excalidocker-linux-amd64.tgz -C amd64/ && rm amd64/excalidocker-linux-amd64.tgz
cp -r amd64 docker/ci
- name: Download arm64 binary
id: download-arm64
uses: actions/download-artifact@v3
with:
name: excalidocker-linux-arm64
path: arm64

- name: Unzip the arm64 artifacts
id: unzip-arm64
run: |
tar xvf arm64/excalidocker-linux-arm64.tgz -C arm64/ && rm arm64/excalidocker-linux-arm64.tgz
cp -r arm64 docker/ci
- name: Build and push all
uses: docker/build-push-action@v3
with:
context: ./docker/ci/
file: ./docker/ci/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
etolbakov/excalidocker:latest
etolbakov/excalidocker:${{ env.IMAGE_TAG }}
release:
name: Release artifacts
needs: [build-macos, build-linux, docker]
# needs: [build-linux, docker]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "excalidocker"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["Evgeny Tolbakov"]
description = "Utility to convert your docker-compose into excalidraw"
Expand All @@ -17,6 +17,7 @@ serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
serde_yaml = "0.9.21"
clap = {version = "4.0.32", features = ["derive"]}
thiserror = "1.0.40"

[profile.release]
debug = false
56 changes: 45 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
aa:
pwd

current_dir = $(shell pwd)

##########################################################################################
## Development commands
##########################################################################################

r:
cargo build --release
s:
./target/release/excalidocker -h
e1:
./target/release/excalidocker --input-path ./data/compose/docker-compose.yaml --output-path /tmp/result.excalidraw
e2:
./target/release/excalidocker --input-path ./data/compose/docker-compose-large.yaml
e3:
./target/release/excalidocker --output-path /tmp/no.excalidraw
e4:
./target/release/excalidocker --input-path ./data/compose/docker-compose-very-large.yaml

check:
cargo check --all-features
Expand All @@ -20,4 +17,41 @@ fmt:
cargo fmt -- --check

clippy:
cargo clippy -- -D warnings
cargo clippy -- -D warnings

##########################################################################################
## Sample execution commands
##########################################################################################
## currently the Makefile commands follow the convention below:
## <execute><id><arguments>
## 'e' - execute with full option for command line arguments
## 'x' - execute with short option for command line arguments
## 'd' - execute with docker image
## 'i' - provided '--input-path' argument
## 'o' - provided '--output-path' argument
## 's' - provided '--skip-dependencies' argument

e1i:
./target/release/excalidocker --input-path ./data/compose/docker-compose.yaml
e1io:
./target/release/excalidocker --input-path ./data/compose/docker-compose.yaml --output-path /tmp/result.excalidraw

e2i:
./target/release/excalidocker --input-path ./data/compose/docker-compose-large.yaml

e3o:
./target/release/excalidocker --output-path /tmp/no.excalidraw

e4i:
./target/release/excalidocker --input-path ./data/compose/docker-compose-very-large.yaml
e4io:
./target/release/excalidocker --input-path ./data/compose/docker-compose-very-large.yaml --output-path $(shell pwd)/docker-compose-very-large.excalidraw
x4io:
./target/release/excalidocker -i ./data/compose/docker-compose-very-large.yaml -o $(current_dir)/docker-compose-very-large.excalidraw
e4ios:
./target/release/excalidocker --skip-dependencies --input-path ./data/compose/docker-compose-very-large.yaml --output-path $(shell pwd)/docker-compose-very-large.excalidraw

d5i:
docker run --rm -v "$(current_dir)/data/compose/:/tmp/" -e INPUT_PATH=/tmp/docker-compose.yaml etolbakov/excalidocker:latest > produced-by-image.excalidraw
d5is:
docker run --rm -v "$(current_dir)/data/compose/:/tmp/" -e INPUT_PATH=/tmp/docker-compose.yaml -e SKIP_DEPS=true etolbakov/excalidocker:latest > produced-by-image-no-deps.excalidraw
78 changes: 49 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,91 @@ Rust-based utility to convert docker-compose.yaml files into [excalidraw](https:
![excalidocker](./data/img/excalidocker.png)

# Table of Contents
1. [Usage](#usage)
2. [Installation](#installation)
3. [Contributing](#Contributing)
4. [Roadmap](#roadmap)
1. [Motivation](#motivation)
2. [Usage](#usage)
3. [Installation](#installation)
4. [Contributing](#contributing)
5. [Roadmap](#roadmap)

## Motivation
An idea of writing this utility originates from Robin Moffatt's [tweet](https://twitter.com/rmoff/status/1659214185220423685).
![motivation](./data/img/motivation.png)

## Usage
0. Download the latest artifact from [releases](https://github.com/etolbakov/excalidocker-rs/releases) and ungzip it.
### 🐳 Docker image
`excalidocker` is available as a [docker image](https://hub.docker.com/r/etolbakov/excalidocker/tags).
Convert docker-compose files without installing/building. Use it in Github actions for auto documentation.
The sky is the limit.Get the latest image from [docker hub](https://hub.docker.com/r/etolbakov/excalidocker):
```sh
docker pull etolbakov/excalidocker
```
Usage example:
```sh
docker run --rm -v "$(pwd)/data/compose/:/tmp/" -e INPUT_PATH=/tmp/docker-compose.yaml etolbakov/excalidocker:latest > produced-by-image.excalidraw
```
The `produced-by-image.excalidraw` file could be opened in [excalidraw](https://excalidraw.com/) and.... hopefully it won't be too scary 👻 😅.
More command examples are in the [Makefile](/Makefile).

> **Note**
> At the moment only Darwin OS is supported.
### 📚Artifact
Download the latest artifact from [releases](https://github.com/etolbakov/excalidocker-rs/releases) and ungzip it.

To get the `help` menu use:
```sh
./excalidocker -h
```
![release-artifact-output](./data/img/release-artifact-output.png)

The application should be provided with two parameters:
- `--input-path` : `docker-compose.yaml` file path that you would like to convert
- `--output-path` : file path for the output excalidraw file. By default a file is be stored under `"/tmp/<docker-compose-file-name>.excalidraw"`
The output should be similar to:
```sh
Utility to convert docker-compose into excalidraw

Usage: excalidocker [OPTIONS] --input-path <INPUT_PATH>

To see the tool in action use:
Options:
-i, --input-path <INPUT_PATH> file path to the docker-compose.yaml
-s, --skip-dependencies display connecting lines between services; if `true` then only service without the lines are rendered
-o, --output-path <OUTPUT_PATH> file path for the output excalidraw file. By default the file content is sent to console output
-h, --help Print help
-V, --version Print version
```
Usage example:
```sh
./excalidocker --input-path /your/path/docker-compose.yaml --output-path /your/path/result.excalidraw
```
The produced file could be opened in [excalidraw](https://excalidraw.com/) and.... hopefully it won't be too shocking 👻 😅.
> **Warning**
>
> On the first launch the ungzipped artifact I saw the following pop up
> "Mac cannot be opened because it is from an unidentified developer"
> If you are fine with that you can `Control-click` the artifact, then choose `Open` from the shortcut menu.
> Click `Open`. The utility will be saved as an exception to your security settings,
> "Mac cannot be opened because it is from an unidentified developer"
> If you are fine with that you can `Control-click` the artifact, then choose `Open` from the shortcut menu.
> Click `Open`. The utility will be saved as an exception to your security settings,
> and you can open it in the future by double-clicking it just as you can any registered app.
![mac-warning](./data/img/mac-warning.png)

>
> ![mac-warning](./data/img/mac-warning.png)
## Installation
To build `excalidocker` locally, please follow these steps:
1. Install Rust and Cargo if you haven't already. Refer to the official Rust documentation for [installation instructions](https://www.rust-lang.org/tools/install):
2. Clone this repository:
```shell
```sh
git clone https://github.com/etolbakov/excalidocker-rs.git
```
3. Build the project using Cargo:
```shell
```sh
cd excalidocker-rs && cargo build --release
```
There is the `make r` command available in the [Makefile](/Makefile) along with other useful command shortcuts.

## Roadmap
These are the features that I would like to add at some point:
- 📊 visualize more data from a docker-compose file - volumes, network, etc
- 🐳 docker artifact
- 🐧 linux artifact
- 🎨 colour output
- 🦀 varios code improvements/enhancements. Feel free to review/suggest if anything could be done better!
- 👨‍💻 etc
- 📊 visualize more data from a docker-compose file - volumes, network, etc
- 📜 [config file support](https://github.com/etolbakov/excalidocker-rs/issues/7)
- ↔️ [use arrows to connect boxes](https://github.com/etolbakov/excalidocker-rs/issues/6)
- 🦀 various code improvements/enhancements. Feel free to review/suggest if anything could be done better!
- 👨‍💻 etc
## Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.
Contributions are welcome! If you encounter any issues, have suggestions for improvements or would like to [participate](https://github.com/etolbakov/excalidocker-rs/issues) please open an issue or submit a pull request.
## License
Expand Down
Binary file added data/img/motivation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/img/release-artifact-output.png
Binary file not shown.
12 changes: 12 additions & 0 deletions docker/ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ubuntu:22.04

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates

ARG TARGETARCH

ADD $TARGETARCH/excalidocker /excalidocker/bin/

ENV PATH /excalidocker/bin/:$PATH

CMD ["sh", "-c", "excalidocker --input-path ${INPUT_PATH} ${SKIP_DEPS:+ --skip-dependencies}"]
Loading

0 comments on commit 060c43c

Please sign in to comment.