Skip to content

Commit

Permalink
Replace container management scripts with singular adamant_env.sh s…
Browse files Browse the repository at this point in the history
…cript

Fix to make `adamant_env.sh` executable

Apply fix to README.md

Rename compose.yaml->compose.yml
  • Loading branch information
Jbsco committed Jun 20, 2024
1 parent 23f01af commit 8885fe3
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 69 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# $ docker build -t $DOCKER_IMAGE_NAME -f Dockerfile .
#
# For best results use the ./build_image.sh and ./create_container.sh scripts
# For best results use the ./adamant_env.sh script with the `build` and `start` arguments
# provided in this directory.
#
FROM ubuntu:24.04 AS base
Expand Down
16 changes: 8 additions & 8 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ 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/pkgs/container/adamant). This make take a few minutes and ~3 GB of disk space. By default, the container created is named `adamant_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/pkgs/container/adamant). This make take a few minutes and ~3 GB of disk space. By default, the container created is named `adamant_container`. To change this, or the image that the container uses, modify `compose.yml` before running the commands below.

```
$ cd adamant/docker
$ ./create_container.sh
$ ./adamant_env.sh start
```

4. Finally, you can log into the container by running.

```
$ ./login_container.sh
$ ./adamant_env.sh login
```

The first time you log in, the environment will be set up automatically. This can take a few minutes. Note that the `adamant/` directory on your host is shared with the docker container at `~/adamant/`. This allows you to modify files on your host and compile those same files on the container.
Expand All @@ -37,21 +37,21 @@ The first time you log in, the environment will be set up automatically. This ca
Once you have created a container using the section above, you can stop it by running.

```
$ ./stop_container.sh
$ ./adamant_env.sh stop
```

To start the container up again, run:

```
$ ./start_container.sh
$ ./adamant_env.sh start
```

## Testing the Environment

We can make sure the environment is set up correctly by running a component unit test. Below, we login to the container and run the unit test for the Command Router.

```
$ ./login_container.sh
$ ./adamant_env.sh login
```

From within the container run:
Expand All @@ -74,7 +74,7 @@ Next, you can create the Docker image by running:

```
$ cd adamant/docker
$ ./build_image.sh
$ ./adamant_env.sh build
```

This may take several minutes complete. By default, the image created is named `ghcr.io/lasp/adamant:latest`. To change this, modify `docker_config.sh` before running `./build_image.sh`.
This may take several minutes complete. By default, the image created is named `ghcr.io/lasp/adamant:latest`. To change this, modify `compose.yml` before running `./adamant_env.sh build`.
84 changes: 84 additions & 0 deletions docker/adamant_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/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

DOCKER_CONTAINER_NAME="adamant_container"
DOCKER_IMAGE_NAME="ghcr.io/lasp/adamant:latest"
DOCKER_COMPOSE_COMMAND="docker compose"
export DOCKER_CONTAINER_NAME
export DOCKER_IMAGE_NAME
export DOCKER_COMPOSE_COMMAND
${DOCKER_COMPOSE_COMMAND} version &> /dev/null
if [ "$?" -ne 0 ]; then
export DOCKER_COMPOSE_COMMAND="docker-compose"
fi

# Helper function to print out command as executed:
execute () {
echo "$ $@"
eval "$@"
}

set -e

usage() {
echo "Usage: $1 [start, stop, login, push, build, remove]" >&2
echo "* start: create and start the adamant container" >&2
echo "* stop: stop the running adamant container" >&2
echo "* login: login to the adamant 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" >&2
exit 1
}

if [ "$#" -eq 0 ]; then
usage $0
fi

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 exec -it -u user ${DOCKER_CONTAINER_NAME} //bin//bash"
;;
push )
execute "docker push ${DOCKER_IMAGE_NAME}"
;;
build )
execute "docker build --progress=plain -t ${DOCKER_IMAGE_NAME} -f Dockerfile ."
;;
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 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
;;
esac
4 changes: 0 additions & 4 deletions docker/build_image.sh

This file was deleted.

13 changes: 13 additions & 0 deletions docker/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: adamant
services:
adamant:
container_name: adamant_container
volumes:
- type: bind
source: ../../adamant
target: /home/user/adamant
extra_hosts:
- host.docker.internal:host-gateway
network_mode: host
image: ghcr.io/lasp/adamant:latest
command: sleep infinity
24 changes: 0 additions & 24 deletions docker/create_container.sh

This file was deleted.

12 changes: 0 additions & 12 deletions docker/docker_config.sh

This file was deleted.

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 8885fe3

Please sign in to comment.