Skip to content

Commit

Permalink
Add singular script adamant_env.sh to handle container creation
Browse files Browse the repository at this point in the history
Convert Docker run script to Docker Compose (`docker compose up -d`)

Make `adamant_env.sh` executable

Add all usage args to `adamant_env.sh` output when run with no args

Reword `adamant_env.sh` output to be more approachable to users

Change `stop` arg to stop the container rather than remove

Remove scripts replaced by `adamant_env.sh`

Retain and use `docker_config.sh` for user configuration

Add Docker Compose network mode for changes in lasp#24

Apply `compose.yaml` fixes for Windows

Rename compose.yaml->compose.yml

Update compose.yml to use docker_config.sh vars

Improve `adamant_env.sh` input handling

Convert remaining `docker` commands to `docker-compose`

Fix script `build` arg to function with `docker-compose`
  • Loading branch information
Jbsco committed Jun 6, 2024
1 parent 34c563a commit 6668e3a
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 49 deletions.
3 changes: 2 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This procedure is used to create a new Docker container that hosts the Adamant b
$ git clone https://github.com/lasp/adamant.git
```

3. Next, tell Docker to create a new container from the [pre-built image](https://github.com/lasp/adamant_example/pkgs/container/adamant_example). This make take a few minutes and ~3 GB of disk space. By default the container created is named `adamant_example_container`. To change this, or the image that the container uses, modify `docker_config.sh` before running the commands below.
3. Next, tell Docker to create a new container from the [pre-built image](https://github.com/lasp/adamant_example/pkgs/container/adamant_example). This make take a few minutes and ~3 GB of disk space. By default the container created is named `adamant_example_container`. To change this, or the image that the container uses, modify `docker_config.sh` before running the commands below.

```
Expand Down Expand Up @@ -76,4 +77,4 @@ Next, you can create the Docker image by running:
$ ./build_image.sh
```

This may take several minutes to complete. By default, the image created is named `ghcr.io/lasp/adamant_example:latest`. To change this, modify `docker_config.sh` before running `./build_image.sh`.
This may take several minutes to complete. By default, the image created is named `ghcr.io/lasp/adamant_example:latest`. To change this, modify `docker_config.sh` before running `./adamant_env.sh build`.
76 changes: 76 additions & 0 deletions docker/adamant_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

set +e

if ! command -v docker &> /dev/null
then
if command -v podman &> /dev/null
then
function docker() {
podman $@
}
else
echo "Neither docker nor podman found!!!"
exit 1
fi
fi

set -e

. ${this_dir}/docker_config.sh

DOCKER_COMPOSE_COMMAND="docker compose"
DOCKER_COMPOSE_CONFIG="${this_dir}/compose.yml"
export DOCKER_COMPOSE_COMMAND
${DOCKER_COMPOSE_COMMAND} version &> /dev/null
if [ "$?" -ne 0 ]; then
export DOCKER_COMPOSE_COMMAND="docker-compose"
fi

usage() {
echo "Usage: $1 [start, stop, login, push, build, remove]" >&2
echo "* start: create and start the adamant_example container" >&2
echo "* stop: stop the running adamant_example container" >&2
echo "* login: login to the adamant_example container" >&2
echo "* push: push the image to the Docker registry" >&2
echo "* build: build the image from the Dockerfile" >&2
echo "* remove: remove network and volumes for adamant_example" >&2
exit 1
}

case $1 in
start )
execute "${DOCKER_COMPOSE_COMMAND} -f compose.yml up -d"
echo ""
echo "Run \"./adamant_env.sh login\" to log in."
;;
stop )
execute "${DOCKER_COMPOSE_COMMAND} -f compose.yml stop"
;;
login )
execute "${DOCKER_COMPOSE_COMMAND} -f ${DOCKER_COMPOSE_CONFIG} exec -it -u user ${PROJECT_NAME} //bin//bash"
;;
push )
execute "${DOCKER_COMPOSE_COMMAND} -f ${DOCKER_COMPOSE_CONFIG} push ${DOCKER_IMAGE_NAME}"
;;
build )
execute "${DOCKER_COMPOSE_COMMAND} -f ${DOCKER_COMPOSE_CONFIG} build"
;;
remove )
if [ "$2" == "force" ]
then
execute "${DOCKER_COMPOSE_COMMAND} -f compose.yml down -t 30 -v"
else
echo "Are you sure? This removes ALL docker volumes and all Adamant Example data! (1-Yes / 2-No)"
select yn in "Yes" "No"; do
case $yn in
Yes ) execute "${DOCKER_COMPOSE_COMMAND} -f compose.yml down -t 30 -v"; break;;
No ) exit;;
esac
done
fi
;;
* )
usage $0
;;
esac
4 changes: 0 additions & 4 deletions docker/build_image.sh

This file was deleted.

16 changes: 16 additions & 0 deletions docker/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: adamant_example
services:
adamant_example:
container_name: ${DOCKER_CONTAINER_NAME}
volumes:
- type: bind
source: ../../adamant
target: /home/user/adamant
- type: bind
source: ../../adamant_example
target: /home/user/adamant_example
extra_hosts:
- host.docker.internal:host-gateway
network_mode: host
image: ${DOCKER_IMAGE_NAME}
command: sleep infinity
24 changes: 0 additions & 24 deletions docker/create_container.sh

This file was deleted.

Empty file modified docker/docker_config.sh
100755 → 100644
Empty file.
4 changes: 0 additions & 4 deletions docker/login_container.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/push_image.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/remove_container.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/start_container.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/stop_container.sh

This file was deleted.

0 comments on commit 6668e3a

Please sign in to comment.