Skip to content

Commit 73bf37a

Browse files
committed
Simplify variables.sh, unify base image and time zone usage in dockerfile
1 parent 34f91ae commit 73bf37a

4 files changed

Lines changed: 23 additions & 26 deletions

File tree

.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ XAUTH=/tmp/.docker.xauth
44
AVAILABLE_CORES=$(($(nproc) - 1))
55

66
DOCKER_USER=todo-docker-user
7+
BASE_IMAGE=todo-base-image
78
IMAGE_NAME=todo-image-name
9+
IMAGE_USER=todo-image-user
810
IMAGE_TAG=latest
11+
TIME_ZONE=$(cat /etc/timezone 2>/dev/null || readlink /etc/localtime | sed 's|.*/zoneinfo/||')
12+
TIME_ZONE=${TIME_ZONE:-UTC}
913

1014
CONTAINER_NAME=${IMAGE_NAME}
11-
IMAGE_USER=todo-image-user
1215
HOME_FOLDER=/home/${IMAGE_USER}
1316
CODE_FOLDER=${IMAGE_NAME}
1417

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ Docker and singularity is not a must unless you cannot install some dependencies
2525

2626
Continue on a machine where you have docker permission, HPC clusters usually restrict docker access for security reasons
2727

28-
1. Modify `todo-docker-user`, `todo-image-name`, `todo-image-user` in [.env](.env)
28+
1. Modify `todo-docker-user`, `todo-base-image`, `todo-image-name`, `todo-image-user` in [.env](.env)
2929

30-
- [.env](env) will be loaded when you use docker compose for build/run/push/...
30+
- [.env](env) will be loaded when you use docker compose for build/run/push
3131
- `todo-docker-user` refers to your docker hub account username
32+
- `todo-base-image` is the image dockerfile is based on, such as `nvidia/cuda:13.0.0-cudnn-devel-ubuntu24.04`
3233
- `todo-image-user` refers to the default user inside the image, which is used to determine home folder
3334

3435
1. Modify the service name from `todo-service-name` to your service name in [docker-compose.yml](docker-compose.yml), add additional volume mounting options such as dataset directories

docker/latest/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Do not add --platform=linux/blabla since this is intended for multiplatform builds
2-
FROM nvidia/cuda:13.0.0-cudnn-devel-ubuntu24.04
2+
FROM ${BASE_IMAGE}
33
ENV HOME=${HOME_FOLDER}
44
WORKDIR ${HOME_FOLDER}/
55

6+
# Make home folder if not exists
7+
RUN mkdir -p ${HOME_FOLDER}
8+
69
# Fix apt install stuck problem
710
ENV DEBIAN_FRONTEND=noninteractive
811
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
@@ -23,8 +26,8 @@ RUN apt update -o Acquire::Check-Valid-Until=false -o Acquire::AllowInsecureRepo
2326

2427
# fix local time problem
2528
RUN apt-get install -y --no-install-recommends tzdata && \
26-
ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime && \
27-
echo "America/New_York" > /etc/timezone && \
29+
ln -fs /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime && \
30+
echo "${TIME_ZONE}" > /etc/timezone && \
2831
dpkg-reconfigure --frontend noninteractive tzdata
2932

3033
# update all obsolete packages to latest, install sudo, and cleanup
@@ -34,7 +37,7 @@ RUN apt update -o Acquire::Check-Valid-Until=false -o Acquire::AllowInsecureRepo
3437
apt autoremove -y && \
3538
apt autoclean -y
3639

37-
# Install some goodies
40+
# Install some goodies
3841
RUN apt-get install -y --no-install-recommends \
3942
build-essential \
4043
clang-format \

scripts/variables.sh

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# Copyright Ⓒ 2024 Mukai (Tom Notch) Yu
99
#
1010

11+
set -euo pipefail
12+
1113
resolve_host_path() {
1214
local p="$1"
1315
[ -n "$p" ] || {
@@ -27,24 +29,12 @@ PY
2729
fi
2830
}
2931

32+
set -a
33+
set +u
3034
. "$(dirname "$0")"/../.env
35+
set -u
36+
set +a
3137

32-
export XSOCK
33-
export XAUTH
34-
export AVAILABLE_CORES
35-
36-
export DOCKER_USER
37-
export IMAGE_NAME
38-
export IMAGE_TAG
39-
40-
export CONTAINER_NAME
41-
export IMAGE_USER
42-
export HOME_FOLDER
43-
export CODE_FOLDER
44-
45-
export HOST_UID
46-
export HOST_GID
47-
export HOST
48-
export HOSTNAME
49-
50-
export BUILDER
38+
# export any additional derived variables here if needed, e.g. resolved absolute paths
39+
# SOME_PATH="$(resolve_host_path "${SOME_PATH:-}")"
40+
# export SOME_PATH

0 commit comments

Comments
 (0)