You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

  1. #!/bin/bash
  2. set -euo pipefail
  3. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." >/dev/null 2>&1 && pwd )"
  4. # Parse command line args
  5. if [ "$#" -ne 1 ]; then
  6. echo "Usage: $0 <target>"
  7. echo "Supported targets: stretch, buster"
  8. exit 1
  9. fi
  10. if [ "$1" == "buster" ]; then
  11. TARGET=buster
  12. elif [ "$1" == "stretch" ]; then
  13. TARGET=stretch
  14. else
  15. echo "Invalid target: $1"
  16. exit 1
  17. fi
  18. # Determine image
  19. IMAGE=rust:1-$TARGET
  20. function log {
  21. echo -e "\033[32;1m==> ${1}\033[0m"
  22. }
  23. log "Pulling image $IMAGE..."
  24. docker pull $IMAGE
  25. log "Starting container..."
  26. CID=$(docker run --rm -td $IMAGE)
  27. log "Copying project files..."
  28. docker cp "$DIR" "$CID":/code/
  29. log "Starting build..."
  30. docker exec "$CID" /bin/bash -c "cd /code && cargo build --release"
  31. log "Copying binaries..."
  32. mkdir -p target/docker/$TARGET/
  33. docker cp "$CID":/code/target/release/acmed target/docker/$TARGET/
  34. docker cp "$CID":/code/target/release/tacd target/docker/$TARGET/
  35. log "Stopping and removing container..."
  36. docker stop "$CID"
  37. log "Done! Find your binaries in the target/docker/$TARGET/ directory."