Skip to content

Commit

Permalink
Merge branch 'dev/docker-cli' into dev/v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sk33z3r committed Jun 23, 2022
2 parents 5524a34 + bdc0d93 commit d698bd3
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 35 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/image-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Build the Docker image
run: docker-compose build
-
name: Checkout Repository
uses: actions/checkout@v3
with:
submodules: recursive
-
name: Build the GUI image
run: docker-compose build
-
name: Build the CLI image
run: docker build -t sk33z3r/loopygen-cli:${{ env.HUB_TAG }} -f Dockerfile.cli .
9 changes: 8 additions & 1 deletion .github/workflows/image-push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ jobs:
username: ${{ secrets.HUB_USER }}
password: ${{ secrets.HUB_KEY }}
-
name: Build and push
name: Build and push GUI images
uses: docker/build-push-action@v2
with:
push: true
tags: sk33z3r/loopygen:${{ env.HUB_TAG }}, sk33z3r/loopygen:latest
-
name: Build and push GUI images
uses: docker/build-push-action@v2
with:
file: "{{defaultContext}}/Dockerfile.cli"
push: true
tags: sk33z3r/loopygen-cli:${{ env.HUB_TAG }}, sk33z3r/loopygen-cli:latest
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ ADD ./js ./js
ADD ./index.php ./index.php
ADD ./docker.sh ./docker.sh
ADD ./.version ./.version
RUN ls -l
# run nginx
EXPOSE 80
STOPSIGNAL SIGKILL
Expand Down
35 changes: 35 additions & 0 deletions Dockerfile.cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM python:3.9-alpine3.15 AS python_modules
# add openssh and clean
RUN apk --no-cache --update add build-base jpeg-dev libffi-dev

# install python modules
ADD python/requirements.txt /generator.txt
ADD python/hello_loopring/requirements.txt /hello_loopring.txt
RUN pip install -r /generator.txt -r /hello_loopring.txt

FROM node:16-alpine3.15 as node_modules
# Set workdir initially just for npm to install
WORKDIR /usr/src/app
# Install modules
ADD ipfs-hash/package*.json ./
RUN npm install --omit=dev
RUN npm install --location=global pkg
# Install app files, compile to native binary
ADD ipfs-hash/* ./
RUN pkg ./cli.js -o ./ipfs-cid-linux

FROM python:3.9-alpine3.15
# define workdir
WORKDIR /loopygen
# install python3.9 and ffmpeg
RUN apk --no-cache --update add ffmpeg bash
# get compiled modules from previous stages
COPY --from=python_modules /usr/local/lib/python3.9 /usr/local/lib/python3.9
COPY --from=node_modules /usr/src/app/ipfs-cid-linux /usr/bin/cid
# add scripts
ADD dockerfiles/scripts/* /usr/local/bin/
# add app files
ADD ./python ./python
ADD ./.version ./.version
RUN mkdir -p ./php && touch php/progress.json
CMD ["bash"]
157 changes: 149 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,156 @@

This is the unofficial Loopring Python Image Generator and Minter on Layer 2.

⚠️ **NEVER SHARE YOUR PRIVATE KEY OR API KEY WITH ANYONE** ⚠️

## New Wiki

1. Python to generate images and metadata according to the standards for the new Layer 2 marketplace.
2. NodeJS to pre-calculate CIDs on images and metadata files.
3. Python to run the batch minting and transfer processes.
4. PHP to tie everything together.
⚠️ **NEVER SHARE YOUR PRIVATE KEYS OR PASSPHRASES WITH ANYONE** ⚠️

Checkout the [Wiki pages](https://loopygen.ezl2.app) for up to date info on using the app!

Checkout the [issues section](https://github.com/sk33z3r/LooPyGen/issues) to report any problems, make feature requests, or keep up with our progress!

## LooPyGen CLI

The LooPyGen CLI client is run in Docker, but on-demand and headless as opposed to as a service through the GUI client. Below you will find a list the command reference, and how to pull the latest images and helper scripts.

**Notes**:

* You can clean up old images with: `docker image prune`
* Your config files are encrypted and stored in a Docker volume that is persistent on updates. Destroy the volume with: `docker volume prune`
* If you desire to access the shell of the container for any reason, do so with: `./loopygen-cli.sh bash`
* If you pass your config passphrase on the command line, it should be base64 encoded first. All transfer and mint commands accept this additional argument:
```shell
--configpass $(echo -n "passphrase" | basenc --base64)
```

Download the script from GitHub with to your local working directory

```shell
$ wget -O ./loopygen-cli.sh https://github.com/sk33z3r/LooPyGen/blob/main/cli.sh && chmod +x loopygen-cli.sh
```

Pull the latest image

```shell
$ ./loopygen-cli.sh update
```

Run a command

```shell
$ ./loopygen-cli.sh {command}
```

### Commands

Replace `{command}` with one of the below commands.

<details>
<summary>Show Config Commands</summary>

Encrypt your mint configuration

```shell
encrypt --mint
```

Encrypt your transfer configuration

```shell
encrypt --transfer
```

</details>

<details>
<summary>Show Image Generator Commands</summary>

Basic run:

```shell
generate --count XXX
```

Delete previously generated images before generating a new set:

```shell
generate --empty --count XXX
```

Start generating from a specific ID number:

```shell
generate --count XXX --id YY
```

If you have a beefy computer, you can try to generate images simultaneously to speed up the process:

```shell
generate --count XXX --threaded
```

</details>

<details>
<summary>Show Metadata Generator Commands</summary>

Basic run, after generating images:

```shell
metadata
```

Delete previously generated metadata before generating a new set:

```shell
metadata --empty
```

</details>

<details>
<summary>Show Minting Commands</summary>

Batch mint a collection:

```shell
mint --name <my_nft_collection> --amount 1
```

Mint a specific set of IDs:

```shell
mint --name <my_nft_collection> --start <startID> --end <endID> --amount 1
```

Mint a single CID:

```shell
mint --cid Qmau1Sx2hLTkLmXsu2dD28yMZtL3Pzs2uKqP2MeHZPm93V --amount 100
```

Test run a mint (shows only what the script _would_ do, but doesn't actually do it):

```shell
mint --name <my_nft_collection> --testmint --amount 100
```

</details>

<details>
<summary>Show CID Calculator Commands</summary>

To scan CID files, input a path relative to your working directory.

The file must be at your current level or lower, and not outside of the directory. For instance, `../other-dir/somefile` would not work.

CIDv0:

```shell
cid ./relative/path/to/file
```

CIDv1:

```shell
cid --cid-version=1 ./relative/path/to/file
```
</details>
56 changes: 56 additions & 0 deletions cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

name="loopygen-cli"
tag="sk33z3r/$name:1.0.1a"

update() {
cat <<EOF
+-------------------------------------------------+
| |
| ░▒█░░░░▄▀▀▄░▄▀▀▄░▒█▀▀█░█░░█░▒█▀▀█░█▀▀░█▀▀▄ |
| ░▒█░░░░█░░█░█░░█░▒█▄▄█░█▄▄█░▒█░▄▄░█▀▀░█░▒█ |
| ░▒█▄▄█░░▀▀░░░▀▀░░▒█░░░░▄▄▄▀░▒█▄▄▀░▀▀▀░▀░░▀ |
| |
| Created and Maintained By: |
| sk33z3r.eth |
| itsmonty.eth |
| |
+-------------------------------------------------+
EOF
echo "Updating LooPyGen CLI..."
docker pull $tag
echo "...done!"
}

usage() {
cat <<EOF
LooPyGen CLI Utility Script
Usage: $0 [command]
Commands:
update | Pull the latest image
secrets | Force remove the secrets Docker volume
{command} | Run a command inside the container
EOF
}

case $1 in
update) update;;
secrets) docker volume rm -f $name;;
-h|-help|help) usage;;
cid) # only mount local directory and set a new workdir inside the container
docker run -it --rm --name $name \
-w /scan \
-v $PWD:/scan \
$tag "$@"
;;
*) # run a command inside a self-destructing container
docker run -it --rm --name $name \
-v $name:/loopygen/.secrets \
-v $PWD/collections:/loopygen/collections:rw \
$tag "$@"
;;
esac
33 changes: 19 additions & 14 deletions docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ if [ -z $HUB_TAG ]; then
if [ $branch == "main" ]; then
branch="latest"
fi
if [ -f .env ]; then
cat .env | sed "s/^HUB_TAG=.*$/HUB_TAG=$branch/g" > .temp
mv .temp .env
fi
else
branch=$HUB_TAG
if [ $branch == "main" ]; then
branch="latest"
fi
fi

if [ $branch == "main" ]; then
branch="latest"
fi

tag="sk33z3r/loopygen:$branch"
cli_tag="sk33z3r/loopygen-cli:$branch"

checkDotenv() {
uid=$(id -u)
Expand All @@ -57,11 +55,15 @@ checkDotenv() {
fi
}

ci() {
local_hub() {
docker login -u "$HUB_USER" -p "$HUB_KEY" &&
echo "Building image with tag: $tag"
echo "Building GUI image with tag: $tag"
docker build -t $tag . &&
echo "Building CLI image with tag: $cli_tag"
docker build -t $cli_tag -f Dockerfile.cli . &&
echo "Pushing images to hub..."
docker push $tag &&
docker push $cli_tag &&
docker logout
}

Expand Down Expand Up @@ -132,12 +134,12 @@ remove_start_menu_shortcuts() {
usage() {
cat <<EOF
LooPyGen Docker Environment Utility Script
LooPyGen v$version Docker Utility Script
Usage: $0 [command]
Commands:
build | Build the container locally
build | Build the images locally
reload | Tear down and rebuild the container
update | Update and reload the repository
up | Spin up container
Expand All @@ -146,14 +148,17 @@ cat <<EOF
remove_start_menu | Remove Windows Start Menu
migrate | Migrate collection files
container | Runs commands for the container, meant for Docker
ci | Build, tag, and push container to Docker Hub
hub | Build, tag, and push images to Docker Hub
{command} | Run a command inside the container
EOF
}

case $1 in
build) docker-compose build;;
build)
docker-compose build &&
docker build -t $cli_tag -f Dockerfile.cli .
;;
reload) reload;;
update) update;;
up)
Expand Down Expand Up @@ -186,7 +191,7 @@ case $1 in
echo "$startup_msg"
nginx -g "daemon off;"
;;
ci) ci;;
hub) local_hub;;
-h|-help|help) usage;;
*)
if ! $(docker ps -q --filter "name=loopygen" | grep -q .); then
Expand Down
Loading

0 comments on commit d698bd3

Please sign in to comment.