Compare commits

..

8 Commits

Author SHA1 Message Date
Daniel Legt 44d4237bec Fixed Static folder push 2024-01-22 02:34:27 +02:00
Daniel Legt f2c84fb6b2 Fixed Dockerfile 2024-01-22 02:23:43 +02:00
Daniel Legt 4f50819f92 Production docker-compose.yml updates 2024-01-22 02:12:18 +02:00
Daniel Legt 6117157598 DockerFile link to repository
* Fixed issue
2024-01-22 02:01:39 +02:00
Daniel Legt 79e44bd88a + Production docker-compose.yml 2024-01-22 01:59:38 +02:00
Daniel Legt c556e3827b Updated deploy 2024-01-22 01:58:43 +02:00
Daniel Legt 63c92ac272 Docker Implementation 2024-01-22 01:49:13 +02:00
Daniel Legt 10bb300087 * Updated README 2024-01-22 00:47:09 +02:00
9 changed files with 180 additions and 8 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
/**
!main.go
!/lib
!/templates
!/static
!/go.mod
!/go.sum

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ snapshots.dat
dist dist
data.db data.db
data.sqlite data.sqlite
dev_data

53
Dockerfile Normal file
View File

@ -0,0 +1,53 @@
# Build Stage
FROM debian:bullseye-slim
ENV IS_DOCKER TRUE
LABEL org.opencontainers.image.source https://github.com/JustKato/drive-health
# Install build dependencies and runtime dependencies
RUN apt-get update && apt-get install -y \
gcc \
musl-dev \
libsqlite3-dev \
libsqlite3-0 \
wget \
&& rm -rf /var/lib/apt/lists/*
# Manually install Go 1.21
ENV GOLANG_VERSION 1.21.0
RUN wget https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz -O go.tgz \
&& tar -C /usr/local -xzf go.tgz \
&& rm go.tgz
ENV PATH /usr/local/go/bin:$PATH
# Set the environment variable for Go
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$PATH
ENV GO111MODULE=on
# Create the directory and set it as the working directory
WORKDIR /app
# Copy the Go files and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the source from the current directory to the Working Directory inside the container
COPY . .
# Build the Go app
RUN go build -o drive-health
# Cleanup build dependencies to reduce image size
RUN apt-get purge -y gcc musl-dev libsqlite3-dev wget \
&& apt-get autoremove -y \
&& apt-get clean
# Expose the necessary port
EXPOSE 8080
# Volume for external data
VOLUME [ "/data" ]
# Command to run the executable
CMD ["./drive-health"]

View File

@ -2,7 +2,7 @@
Drive Health is a program written in golang to help with tracking and monitoring of your hardware's temperature. Drive Health is a program written in golang to help with tracking and monitoring of your hardware's temperature.
This tool has been created by [me](https://danlegt.com) with the purpose of installing it in different servers I own with different configurations to help keep track of the temperature of different hard-disks, ssds, nvme drives, etc... The testing has been very limited to only 4 different computers and not on laptops so expect some mishaps. This tool has been with the purpose of installing it in different servers I own with different configurations to help keep track of the temperature of different hard-disks, ssds, nvme drives, etc... The testing has been very limited to only 4 different computers and not on laptops so expect some mishaps.
![UI Example](./media/design_v1.webp) ![UI Example](./media/design_v1.webp)

View File

@ -1,17 +1,19 @@
#!/bin/bash #!/bin/sh
set -o pipefail
set -u
APP_NAME="drive-health" APP_NAME="drive-health"
DIST_DIR="dist" DIST_DIR="${DIST_DIR:-dist}"
# Create the dist directory if it doesn't exist # Create the dist directory if it doesn't exist
mkdir -p $DIST_DIR mkdir -p $DIST_DIR
# Build the application # Build the application
echo "Building the application..." echo "Building the application..."
GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/$APP_NAME GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -o $DIST_DIR/$APP_NAME
# Copy additional resources (like .env, static files, templates) to the dist directory # echo "Copying additional resources..."
echo "Copying additional resources..." cp -r static templates $DIST_DIR/
cp -r .env static templates $DIST_DIR/
echo "Compilation and packaging completed." echo "Compilation and packaging completed."

65
deploy.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/bash
# Function to display messages in color
echo_color() {
color=$1
text=$2
case $color in
"green") echo -e "\033[0;32m$text\033[0m" ;;
"yellow") echo -e "\033[0;33m$text\033[0m" ;;
"red") echo -e "\033[0;31m$text\033[0m" ;;
*) echo "$text" ;;
esac
}
# Getting GIT_VERSION from the most recent tag or commit hash
GIT_VERSION=$(git describe --tags --always)
if [ -z "$GIT_VERSION" ]; then
echo_color red "Error: Unable to determine GIT_VERSION."
exit 1
fi
# Run tests before proceeding
echo_color yellow "Running tests..."
if ! go test; then
echo_color red "Tests failed. Cancelling build process."
exit 1
fi
echo_color green "All tests passed successfully."
echo_color green "Starting the Docker build process with version $GIT_VERSION..."
LATEST_IMAGE_NAME="ghcr.io/justkato/drive-health:latest"
IMAGE_NAME="ghcr.io/justkato/drive-health:$GIT_VERSION"
echo_color yellow "Image to be built: $IMAGE_NAME"
# Confirmation to build
read -p "Are you sure you want to build an image? (y/N) " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
# Building the Docker image
echo "Building Docker image: $IMAGE_NAME"
docker build --no-cache -t $IMAGE_NAME .
# Also tag this build as 'latest'
echo "Tagging image as latest: $LATEST_IMAGE_NAME"
docker tag $IMAGE_NAME $LATEST_IMAGE_NAME
else
echo_color red "Build cancelled."
exit 1
fi
# Prompt to push the image
read -p "Push image to repository? (y/N) " push_response
if [[ "$push_response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
# Pushing the image
echo "Pushing image: $IMAGE_NAME"
docker push $IMAGE_NAME
# Pushing the 'latest' image
echo "Pushing latest image: $LATEST_IMAGE_NAME"
docker push $LATEST_IMAGE_NAME
else
echo_color red "Push cancelled."
fi
echo_color green "Ending the Docker build process..."

14
docker-compose.dev.yml Normal file
View File

@ -0,0 +1,14 @@
version: "3.8"
services:
drive-health:
# Build the current image
build: .
# Read straight from the .env file, or use the environment path
env_file:
- .env
volumes:
- ./dev_data:/data
# Setup application ports
ports:
- 8080:8080

17
docker-compose.prod.yml Normal file
View File

@ -0,0 +1,17 @@
version: "3.8"
services:
drive-health:
# Latest image pull, mention the specific version here please.
image: ghcr.io/justkato/drive-health:latest
# Restart in case of crashing
restart: unless-stopped
# Load environment variables from .env file
env_file:
- .env
# Mount the volume to the local drive
volumes:
- ./data:/data
# Setup application ports
ports:
- 5003:8080

View File

@ -17,6 +17,8 @@ type DHConfig struct {
IdentityUsername string `json:"identityUsername"` IdentityUsername string `json:"identityUsername"`
IdentityPassword string `json:"identityPassword"` IdentityPassword string `json:"identityPassword"`
IsDocker bool `json:isDocker`
DebugMode bool `json:"debugMode"` DebugMode bool `json:"debugMode"`
} }
@ -36,6 +38,8 @@ func GetConfiguration() *DHConfig {
IdentityUsername: "admin", IdentityUsername: "admin",
IdentityPassword: "admin", IdentityPassword: "admin",
IsDocker: false,
Listen: ":8080", Listen: ":8080",
} }
@ -79,5 +83,13 @@ func GetConfiguration() *DHConfig {
} }
} }
if val, exists := os.LookupEnv("IS_DOCKER"); exists {
if isDocker, err := strconv.ParseBool(val); err == nil {
config.IsDocker = isDocker
config.DatabaseFilePath = "/data/data.sqlite"
}
}
return config return config
} }