Skip to content

Commit

Permalink
Added documents
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpye committed Feb 14, 2023
1 parent 9a5aeca commit bce9380
Show file tree
Hide file tree
Showing 25 changed files with 1,371 additions and 210 deletions.
142 changes: 125 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,97 @@
# Cimpex - Container Import Export Utility
Export and import docker images from a registry without docker

# Description
## Description
The solution enables you to easily export and import Docker containers from a registry without the need to install docker.
It also can be run as a web-server allowing you to perform the Import Export via REST API

# When to use Cimpex
## When to use Cimpex
Cimpex can be used when you want to automate the import and export of docker images from a registry if you need to transport images between sites that don't have internet access. Also can be used as part of your CI/CD pipeline.

---
## Requirements
* A Container registry to import or export from.
* you will need to install go 1.8 [https://go.dev/doc/install](https://go.dev/doc/install) to run and install Cimpex

---

## Project folders
Below is a description cimpex project folders and what they contain
| Folder | Description |
|-----------|---|
| charts | Contains the helm chart for cimpex |
| docs | Contains the swagger documents |
| documents | Contains cli and api markdown files |
| modules | Contains cimpex modules and code |
| config | Contains Example payload config files |
| cmd | Contains code for cimpex CLI |
| | |

---

## Installation

```yaml
go install github.com/Mrpye/cimpex
```

## Run as a container
1. Clone the repository

<details>
<summary>1. Clone the repository</summary>

```
git clone https://github.com/Mrpye/cimpex.git
```
</details>

<details>
<summary>2. Build the container as API endpoint</summary>

2. Build the container as API endpoint
```
sudo docker build . -t cimpex:v1.0.0 -f Dockerfile
```
3. Run the container

</details>

<details>
<summary>3. Run the container</summary>

```
sudo docker run -d -p 9020:8080 --name=cimpex --restart always -v /host_path/images:/go/bin/images --env=BASE_FOLDER=/go/bin/images --env=WEB_IP=0.0.0.0 --env=WEB_PORT=8080 -t cimpex:1.0.0
```

</details>

---

### Environment variables
- BASE_FOLDER (set where the images will be exported)
- WEB_IP (set the listening ip address 0.0.0.0 allow from everywhere)
- WEB_PORT (set the port to listen on)


---
## How to use Cimpex CLI
Check out the CLI documentation [here](./documents/cimpex.md)

---

# Using the API

## Run web server
```bash
cimpex web -f /go/bin/images -p 8080 -i 0.0.0.0
```
## Export image from a registry
---

## Examples

<details>
<summary>Export image from a registry</summary>

Export and image fromm a registry with no authentication

``` bash
curl --location --request POST 'http://localhost:9020/export' \
--header 'Content-Type: application/json' \
Expand All @@ -60,6 +103,7 @@ curl --location --request POST 'http://localhost:9020/export' \
```
Export from a registry with authentication
```bash
curl --location --request POST 'http://172.16.10.237:9020/export' \
--header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' \
Expand All @@ -70,6 +114,10 @@ curl --location --request POST 'http://172.16.10.237:9020/export' \
"ignore_ssl":true
}
```
</details>

<details>
<summary>Export multiple images from a registry</summary>

## Export images from a registry
``` bash
Expand All @@ -87,10 +135,13 @@ curl --location --request POST 'http://localhost:9020/exports' \
}
]
```
</details>
## Import image to a registry
<details>
<summary>Import image to a registry</summary>
specify the name and tag
Import an image and specify the name at tag to use
```bash
curl --location --request POST 'localhost:8080/import' \
Expand All @@ -103,7 +154,7 @@ curl --location --request POST 'localhost:8080/import' \
}'
```
use the name and tag in tar manifest
Import an image and use the name at tag from the tar file
```bash
curl --location --request POST 'localhost:8080/import' \
Expand All @@ -121,34 +172,91 @@ curl --location --request POST 'localhost:8080/import' \
- target (location of the docker image import/export)
- tar (name of the tar file will be saved in the export folder)
- ignore_ssl (Ignore ssl cert)
</details>
---
## Test is alive
<details>
<summary>List images in the folder</summary>
```bash
curl --location --request POST 'localhost:8080/list' \
--header 'Content-Type: application/json'
```
</details>
<details>
<summary>Test is alive</summary>
```bash
curl --location --request GET 'localhost:8080/'
```
Return OK
</details>
---
## cimpex Helm chart
This guide will show you how to build the helm chart package for cimpex, you will need to have helm installed to build the package.
# Helm chart
<details>
<summary>1. Build the helm chart package for cimpex</summary>
```
```bash
# change into the chart directory
cd charts
# Validate the chart
helm lint cimpex
# Package the chart
# Package the cimpex chart
helm package cimpex
```
the helm chart package will be saved under the charts folder cimpex-0.1.0.tgz
</details>
---
## Update the swagger document
The code below shows you how to update the swagger API documents.
If you need more helm on using these tools please refer to the links below
- gin-swagge [https://github.com/swaggo/gin-swagger](https://github.com/swaggo/gin-swagger)
- swag [https://github.com/swaggo/swag](https://github.com/swaggo/swag)
<details>
<summary>1. Install swag</summary>
```bash
#Install swag
go install github.com/swaggo/swag/cmd/swag
```
</details>
<details>
<summary>2. Update APi document</summary>
```bash
#update the API document
swag init
```
</details>
<details>
<summary>3. Update the api.md</summary>
```bash
swagger generate markdown -f .\docs\swagger.json --output .\documents\api.md
```
</details>
---
# To Do
- improve validation and error handling
---
# 3rd party Libraries
https://github.com/google/go-containerregistry
---
# license
cimplex is Apache 2.0 licensed.
2 changes: 1 addition & 1 deletion cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"errors"
"fmt"

"github.com/Mrpye/cimpex/registry"
"github.com/Mrpye/cimpex/modules/registry"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/Mrpye/cimpex/registry"
"github.com/Mrpye/cimpex/modules/registry"
"github.com/spf13/cobra"
)

Expand Down
Loading

0 comments on commit bce9380

Please sign in to comment.