Skip to content

Commit

Permalink
Merge pull request #82 from udx/UAT-84
Browse files Browse the repository at this point in the history
Image experience re-design [UAT-84]
  • Loading branch information
fqjony authored Feb 21, 2025
2 parents 43824cb + 1a129b1 commit a82fa21
Show file tree
Hide file tree
Showing 53 changed files with 3,615 additions and 918 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

# CI/CD and GitHub-related files
ci/*

# macOS system files
.DS_Store
**/.DS_Store
.AppleDouble
.LSOverride

# Editor and IDE files
.idea/
.vscode/
*.swp
*.swo
.github/*

# Documentation files
Expand All @@ -35,3 +47,4 @@ src/*
.vscode/
*.iml
.prettierignore
.DS_Store
118 changes: 85 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ FROM ubuntu:25.04
# Set the maintainer of the image
LABEL maintainer="UDX CAG Team"

# Set environment variables to avoid interactive prompts and set a fixed timezone
# Set base environment variables
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Etc/UTC \
USER=udx \
UID=500 \
GID=500 \
HOME=/home/udx
HOME=/home/udx \
# Worker specific paths
WORKER_BASE_DIR=/opt/worker \
WORKER_CONFIG_DIR=/etc/worker \
WORKER_APP_DIR=/opt/worker/apps \
WORKER_DATA_DIR=/opt/worker/data \
WORKER_LIB_DIR=/usr/local/worker/lib \
WORKER_BIN_DIR=/usr/local/worker/bin \
WORKER_ETC_DIR=/usr/local/worker/etc \
# Add worker bin to PATH
PATH=/usr/local/worker/bin:${PATH} \
# Cloud SDK configurations
CLOUDSDK_CONFIG=/usr/local/configs/gcloud \
AWS_CONFIG_FILE=/usr/local/configs/aws \
AZURE_CONFIG_DIR=/usr/local/configs/azure

# Set the shell with pipefail option
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
Expand All @@ -22,10 +36,10 @@ USER root
# hadolint ignore=DL3015
RUN apt-get update && \
apt-get install -y \
tzdata=2024b-6ubuntu1 \
tzdata=2025a-2ubuntu1 \
curl=8.12.0+git20250209.89ed161+ds-1ubuntu1 \
bash=5.2.37-1ubuntu1 \
apt-utils=2.9.28 \
apt-utils=2.9.30ubuntu1 \
gettext=0.23.1-1 \
gnupg=2.4.4-2ubuntu22 \
ca-certificates=20241223 \
Expand Down Expand Up @@ -110,34 +124,72 @@ RUN groupadd -g ${GID} ${USER} && \
RUN mkdir -p /var/log/supervisor /var/run/supervisor && \
chown -R ${USER}:${USER} /var/log/supervisor /var/run/supervisor

# Copy the CLI tool into the image
COPY lib/cli.sh /usr/local/bin/worker_mgmt
RUN chmod +x /usr/local/bin/worker_mgmt && \
ln -s /usr/local/bin/worker_mgmt /usr/local/bin/worker

# Copy the bin, etc, and lib directories
COPY etc/configs /usr/local/configs
COPY lib /usr/local/lib
COPY bin/entrypoint.sh /usr/local/bin/entrypoint.sh

# Set permissions during build
# Set ownership
RUN chown -R ${UID}:${GID} /usr/local/configs /usr/local/bin /usr/local/lib && \
# Make specific scripts executable
chmod 755 /usr/local/bin/entrypoint.sh /usr/local/lib/process_manager.sh && \
# Set read-only permissions for config files
find /usr/local/configs -type f -exec chmod 644 {} + && \
# Set read-only permissions for library files
find /usr/local/lib -type f ! -name process_manager.sh -exec chmod 644 {} + && \
# Ensure directories are accessible
find /usr/local/configs /usr/local/bin /usr/local/lib -type d -exec chmod 755 {} +

# Create a symbolic link for the supervisord configuration file
RUN ln -sf /usr/local/configs/supervisor/supervisord.conf /etc/supervisord.conf

# Prepare directories for the user and worker configuration
RUN mkdir -p ${HOME} && \
chown -R ${USER}:${USER} ${HOME}
# Create directory structure
RUN mkdir -p \
# Worker directories
${WORKER_CONFIG_DIR} \
${WORKER_APP_DIR} \
${WORKER_DATA_DIR} \
${WORKER_LIB_DIR} \
${WORKER_BIN_DIR} \
${WORKER_ETC_DIR} \
# Environment files directory
${WORKER_CONFIG_DIR}/environment.d \
# User and config directories
${HOME}/.config/worker \
# Cloud SDK config directories
${CLOUDSDK_CONFIG} \
${AWS_CONFIG_FILE%/*} \
${AZURE_CONFIG_DIR} && \
# Create and set permissions for environment files
touch ${WORKER_CONFIG_DIR}/environment && \
chown ${USER}:${USER} ${WORKER_CONFIG_DIR}/environment && \
chmod 644 ${WORKER_CONFIG_DIR}/environment

# Copy worker files
COPY bin/entrypoint.sh ${WORKER_BIN_DIR}/
COPY lib ${WORKER_LIB_DIR}/
COPY etc/configs/worker/default.yaml ${WORKER_CONFIG_DIR}/worker.yaml
COPY etc/configs/supervisor ${WORKER_CONFIG_DIR}/supervisor/

# Make scripts executable and initialize environment
RUN chmod +x ${WORKER_LIB_DIR}/*.sh && \
${WORKER_LIB_DIR}/env_handler.sh init_environment

# Set up CLI tool and create symlink
COPY lib/cli.sh ${WORKER_BIN_DIR}/worker_mgmt
RUN chmod 755 ${WORKER_BIN_DIR}/worker_mgmt && \
ln -sf ${WORKER_BIN_DIR}/worker_mgmt ${WORKER_BIN_DIR}/worker

# Set permissions
RUN \
# Set base ownership
chown -R ${UID}:${GID} \
${WORKER_BASE_DIR} \
${WORKER_CONFIG_DIR} \
${WORKER_LIB_DIR} \
${WORKER_BIN_DIR} \
${HOME} \
${CLOUDSDK_CONFIG} \
${AWS_CONFIG_FILE%/*} \
${AZURE_CONFIG_DIR} && \
# Set directory permissions
find ${WORKER_BASE_DIR} ${WORKER_CONFIG_DIR} ${WORKER_LIB_DIR} ${WORKER_BIN_DIR} -type d -exec chmod 755 {} + && \
# Set base file permissions
find ${WORKER_CONFIG_DIR} -type f -exec chmod 644 {} + && \
find ${WORKER_LIB_DIR} -type f ! -name process_manager.sh -exec chmod 644 {} + && \
# Make specific files executable
chmod 755 \
${WORKER_BIN_DIR}/entrypoint.sh \
${WORKER_BIN_DIR}/worker_mgmt \
${WORKER_LIB_DIR}/process_manager.sh && \
# Set runtime directories permissions
chmod 775 ${WORKER_APP_DIR} ${WORKER_DATA_DIR} && \
# Set home directory executable
chmod 755 ${HOME}

# Set up supervisor configuration
RUN ln -sf ${WORKER_CONFIG_DIR}/supervisor/supervisord.conf /etc/supervisord.conf

# Switch to the user directory
WORKDIR ${HOME}
Expand All @@ -146,7 +198,7 @@ WORKDIR ${HOME}
USER ${USER}

# Set the entrypoint to run the entrypoint script using shell form
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
ENTRYPOINT ["/usr/local/worker/bin/entrypoint.sh"]

# Set the default command
CMD ["tail", "-f", "/dev/null"]
37 changes: 27 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,28 @@ build:
printf "$(COLOR_BLUE)$(SYM_ARROW) Starting Docker build...$(COLOR_RESET)\n"; \
if [ "$(MULTIPLATFORM)" = "true" ]; then \
printf "$(COLOR_BLUE)$(SYM_ARROW) Building for multiple platforms: [linux/amd64, linux/arm64]$(COLOR_RESET)\n"; \
docker buildx build --progress=plain \
--platform linux/amd64,linux/arm64 \
-t $(DOCKER_IMAGE) \
--load . 2>&1 | grep -E "$$filter" || exit 1; \
if [ "$(DEBUG)" = "true" ]; then \
docker buildx build --progress=plain \
--platform linux/amd64,linux/arm64 \
-t $(DOCKER_IMAGE) \
--load .; \
else \
docker buildx build --progress=plain \
--platform linux/amd64,linux/arm64 \
-t $(DOCKER_IMAGE) \
--load . 2>&1 | grep -E "$$filter" || exit 1; \
fi; \
else \
printf "$(COLOR_BLUE)$(SYM_ARROW) Building for local platform$(COLOR_RESET)\n"; \
DOCKER_BUILDKIT=1 docker build \
--progress=plain \
-t $(DOCKER_IMAGE) . 2>&1 | grep -E "$$filter" || exit 1; \
if [ "$(DEBUG)" = "true" ]; then \
DOCKER_BUILDKIT=1 docker build \
--progress=plain \
-t $(DOCKER_IMAGE) .; \
else \
DOCKER_BUILDKIT=1 docker build \
--progress=plain \
-t $(DOCKER_IMAGE) . 2>&1 | grep -E "$$filter" || exit 1; \
fi; \
fi && \
printf "$(COLOR_GREEN)$(SYM_SUCCESS) Docker image build completed$(COLOR_RESET)\n" || \
{ printf "$(COLOR_RED)$(SYM_ERROR) Docker build failed$(COLOR_RESET)\n"; exit 1; }'
Expand Down Expand Up @@ -89,9 +102,13 @@ clean:
test: clean
@printf "$(COLOR_BLUE)$(SYM_ARROW) Running tests...$(COLOR_RESET)\n"
@$(MAKE) run \
VOLUMES="$(TEST_WORKER_CONFIG):/home/$(USER)/worker.yaml:ro $(TEST_SERVICES_CONFIG):/home/$(USER)/services.yaml:ro $(TESTS_TASKS_DIR):/home/$(USER)/tasks:ro $(TESTS_MAIN_SCRIPT):/home/$(USER)/main.sh:ro" \
COMMAND="/home/$(USER)/main.sh" || exit 1
@$(MAKE) log FOLLOW_LOGS=true || exit 1
VOLUMES="$(PWD)/src/tests:/home/udx/tests $(PWD)/src/examples/simple-config/.config/worker/worker.yaml:/home/udx/.config/worker/worker.yaml $(PWD)/src/examples/simple-service/.config/worker/services.yaml:/home/udx/.config/worker/services.yaml $(PWD)/src/examples/simple-service/index.sh:/home/udx/index.sh" \
COMMAND="/home/udx/tests/main.sh"
@printf "$(COLOR_BLUE)$(SYM_ARROW) Following test output...$(COLOR_RESET)\n"
@docker logs -f $(CONTAINER_NAME) & LOGS_PID=$$!; \
docker wait $(CONTAINER_NAME) > /dev/null; EXIT_CODE=$$?; \
kill $$LOGS_PID 2>/dev/null || true; \
exit $$EXIT_CODE
@$(MAKE) clean || exit 1
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) Tests completed successfully$(COLOR_RESET)\n"

Expand Down
2 changes: 1 addition & 1 deletion Makefile.variables
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TESTS_TASKS_DIR ?= ./src/tests/tasks
TEST_WORKER_CONFIG ?= ./src/tests/configs/worker.yaml
TEST_SERVICES_CONFIG ?= ./src/tests/configs/services.yaml
USER = udx
VOLUMES ?= ./src/scripts:/home/$(USER)
VOLUMES ?=
DEBUG ?= false
COMMAND ?=
MULTIPLATFORM ?= false
Expand Down
Loading

0 comments on commit a82fa21

Please sign in to comment.