Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Update build-and-deploy.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
keshon committed Mar 15, 2024
1 parent 80c0493 commit f28a697
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions docker/build-and-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
#!/bin/bash

# Check if "traefik" argument is provided
if [ "$1" == "traefik" ]; then
DOCKER_COMPOSE_COMMAND="docker-compose -f docker-compose.yml -f docker-compose.traefik.yml up -d"
else
DOCKER_COMPOSE_COMMAND="docker-compose -f docker-compose.yml up -d"
fi

# Read .env
if [ -f .env ]; then
# Source the .env file to set environment variables
source .env
else
echo ".env file not found!"
exit 1 # Exit with an error code
exit 1
fi

# Git repo
if [ "$GIT" != "false" ]; then
# Remove old git project
rm -rf ./src
# Make a new git clone
git clone "$GIT_URL" src
else
if [ ! -d "./src" ]; then
echo "src dir not found!"
exit 1 # Exit with an error code
exit 1
fi
fi

# Docker
# - Remove old container (if it exists)
docker-compose down

# - Remove old image (if it exists)
if [ "$(docker images -q "${ALIAS}-image" 2>/dev/null)" ]; then
docker rmi "${ALIAS}-image"
fi

# - Build new docker image from Dockerfile using BuildKit for parallel builds
DOCKER_BUILDKIT=1 docker build -t "${ALIAS}-image" .

# Start new container using docker-compose based on the selected command
eval "$DOCKER_COMPOSE_COMMAND"

# Remove unused images
docker image prune -a
docker system prune --all

0 comments on commit f28a697

Please sign in to comment.