Skip to content

Commit

Permalink
chore: Update Dockerfile to use specified Ubuntu version in the Docke…
Browse files Browse the repository at this point in the history
…r image
  • Loading branch information
paul-ahn-wm committed Jul 5, 2024
1 parent bf489bf commit 35ad901
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 33 deletions.
7 changes: 5 additions & 2 deletions local-docker-env/Dockerfile.boot
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Specifies the version of Ubuntu to be used in the Docker image.
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder

Expand Down Expand Up @@ -39,7 +42,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:latest
FROM ubuntu:${UBUNTU_VERSION}

# Update and upgrade the package list
RUN apt-get update && \
Expand Down Expand Up @@ -85,7 +88,7 @@ RUN rm -rf nodekey

# Run init-boot.sh
RUN chmod a+x bin/init-boot.sh
CMD ./bin/init-boot.sh && tail -f /dev/null
CMD ./bin/init-boot.sh && tail -f logs/log

# Clean up unnecessary packages
RUN apt-get remove -y \
Expand Down
7 changes: 5 additions & 2 deletions local-docker-env/Dockerfile.boot.git
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Specifies the version of Ubuntu to be used in the Docker image.
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder

Expand Down Expand Up @@ -49,7 +52,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:latest
FROM ubuntu:${UBUNTU_VERSION}

# Set environment variables
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
Expand Down Expand Up @@ -106,7 +109,7 @@ RUN rm -rf nodekey

# Run init-boot.sh
RUN chmod a+x bin/init-boot.sh
CMD ./bin/init-boot.sh && tail -f /dev/null
CMD ./bin/init-boot.sh && tail -f logs/log

# Clean up unnecessary packages
RUN apt-get remove -y \
Expand Down
5 changes: 4 additions & 1 deletion local-docker-env/Dockerfile.node
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Specifies the version of Ubuntu to be used in the Docker image.
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder

Expand Down Expand Up @@ -39,7 +42,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:latest
FROM ubuntu:${UBUNTU_VERSION}

# Update and upgrade the package list
RUN apt-get update && \
Expand Down
5 changes: 4 additions & 1 deletion local-docker-env/Dockerfile.node.git
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Specifies the version of Ubuntu to be used in the Docker image.
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder

Expand Down Expand Up @@ -49,7 +52,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:latest
FROM ubuntu:${UBUNTU_VERSION}

# Set environment variables
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
Expand Down
12 changes: 6 additions & 6 deletions local-docker-env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ This document explains how to set up a local testing environment based on the `g
### local-docker.sh

- **Purpose**: Integrated running script for local testing based on the local repository.
- **Usage**: `./local-docker-env/local-docker.sh -a <account_num>`
- **Usage**: `./local-docker-env/local-docker.sh -a <account_num> -v <ubuntu_version>(optional)`

### local-docker-git.sh

- **Purpose**: Integrated running script for local testing based on the Git repository.
- **Usage**: `./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo>`
- **Usage**: `./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo> -v <ubuntu_version>(optional)`

### key-gen.sh

Expand All @@ -31,12 +31,12 @@ This document explains how to set up a local testing environment based on the `g
### docker-compose-gen.sh

- **Purpose**: Generates the `docker-compose.yml` file based on the local repository.
- **Usage**: `./docker-compose-gen.sh -a <account_num> -f <output_file_path>`
- **Usage**: `./docker-compose-gen.sh -a <account_num> -f <output_file_path> -v <ubuntu_version>(optional)`

### docker-compose-gen-git.sh

- **Purpose**: Generates the `docker-compose.yml` file based on the Git repository.
- **Usage**: `./docker-compose-gen-git.sh -a <account_num> -f <output_file_path> -r <repo_url> -b <branch_name>`
- **Usage**: `./docker-compose-gen-git.sh -a <account_num> -f <output_file_path> -r <repo_url> -b <branch_name> -v <ubuntu_version>(optional)`

### init-boot.sh

Expand Down Expand Up @@ -66,11 +66,11 @@ This document explains how to set up a local testing environment based on the `g
### Execution based on the local repository code

```bash
./local-docker-env/local-docker.sh -a <account_num>
./local-docker-env/local-docker.sh -a <account_num> -v <ubuntu_version>(optional)
```

### Execution based on the Git repository code

```bash
./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo>
./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo> -v <ubuntu_version>(optional)
```
12 changes: 11 additions & 1 deletion local-docker-env/docker-compose-gen-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# -f 옵션을 지정하면, 해당 경로에 docker-compose.yml 파일을 생성

# Parse command line arguments
while getopts "a:f:r:b:" opt; do
while getopts "a:f:r:b:v:" opt; do
case $opt in
a)
account_num=$OPTARG
Expand All @@ -24,6 +24,9 @@ while getopts "a:f:r:b:" opt; do
b)
branch_name=$OPTARG
;;
v)
version=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
Expand Down Expand Up @@ -58,6 +61,11 @@ if [ -z "$output_file" ]; then
output_file="docker-compose.yml"
fi

# Set default version if not provided
if [ -z "$version" ]; then
version="latest"
fi

# Generate docker-compose.yml content
cat <<EOF > "$output_file"
services:
Expand All @@ -74,6 +82,7 @@ for ((i=1; i<=account_num; i++)); do
REPO: $repo_url
BRANCH: $branch_name
NODE_NUM: $i
UBUNTU_VERSION: $version
image: wemix/node-boot:latest
hostname: wemix-boot
networks:
Expand All @@ -97,6 +106,7 @@ EOF
REPO: $repo_url
BRANCH: $branch_name
NODE_NUM: $i
UBUNTU_VERSION: $version
image: wemix/node$((i-1)):latest
hostname: wemix-node$((i-1))
networks:
Expand Down
16 changes: 14 additions & 2 deletions local-docker-env/docker-compose-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
# Usage: ./gen-docker-compose.sh -a <account_num> -f <output_config_file>
# -a: 계정 수
# -f: 출력 파일
# -a 옵션은 필수이며, -f 옵션은 선택적
# -a 옵션은 필수이며, -f, -v 옵션은 선택적
# -f 옵션을 지정하지 않으면, 현재 디렉토리에 docker-compose.yml 파일을 생성
# -f 옵션을 지정하면, 해당 경로에 docker-compose.yml 파일을 생성
# -v 옵션을 지정하지 않으면, latest 버전으로 설정
# -v 옵션을 지정하면, 해당 버전으로 설정

# Parse command line arguments
while getopts "a:f" opt; do
while getopts "a:f:v:" opt; do
case $opt in
a)
account_num=$OPTARG
;;
f)
output_file=$OPTARG
;;
v)
version=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
Expand All @@ -38,6 +43,11 @@ if [ -z "$output_file" ]; then
output_file="docker-compose.yml"
fi

# Set default version if not provided
if [ -z "$version" ]; then
version="latest"
fi

# Generate docker-compose.yml content
cat <<EOF > "$output_file"
services:
Expand All @@ -52,6 +62,7 @@ for ((i=1; i<=account_num; i++)); do
dockerfile: Dockerfile.boot
args:
NODE_NUM: $i
UBUNTU_VERSION: $version
image: wemix/node-boot:latest
hostname: wemix-boot
networks:
Expand All @@ -73,6 +84,7 @@ EOF
dockerfile: Dockerfile.node
args:
NODE_NUM: $i
UBUNTU_VERSION: $version
image: wemix/node$((i-1)):latest
hostname: wemix-node$((i-1))
networks:
Expand Down
20 changes: 11 additions & 9 deletions local-docker-env/local-docker-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
current_dir=$(pwd)
export PATH=$PATH:${current_dir}/go-wemix/build/bin

# 필수 인수 확인
if [ "$#" -ne 6 ]; then
echo "Usage: $0 -a <account_num> -b <branch> -r <repo>"
exit 1
fi

# 옵션 파싱
while getopts "a:b:r:" opt; do
while getopts "a:b:r:v:" opt; do
case ${opt} in
a)
ACCOUNT_NUM=$OPTARG
Expand All @@ -22,6 +16,9 @@ while getopts "a:b:r:" opt; do
r)
REPO=$OPTARG
;;
v)
VERSION=$OPTARG
;;
\?)
echo "Usage: $0 -a <account_num> -b <branch> -r <repo>"
exit 1
Expand All @@ -31,10 +28,15 @@ done

# 필수 인수 확인
if [ -z "$ACCOUNT_NUM" ] || [ -z "$BRANCH" ] || [ -z "$REPO" ]; then
echo "Missing required arguments."
echo "Missing required arguments. Usage: $0 -a <account_num> -b <branch> -r <repo>"
exit 1
fi

# Set default version if not provided
if [ -z "$VERSION" ]; then
VERSION="latest"
fi

# key-gen.sh 실행
chmod +x local-docker-env/key-gen.sh
./local-docker-env/key-gen.sh -a "$ACCOUNT_NUM" || { echo "Failed to execute key-gen.sh."; exit 1; }
Expand All @@ -45,7 +47,7 @@ chmod +x local-docker-env/config-gen.sh

# BRANCH와 REPO 정보를 입력으로 받아 docker-compose-gen.sh 실행
chmod +x local-docker-env/docker-compose-gen-git.sh
./local-docker-env/docker-compose-gen-git.sh -a "$ACCOUNT_NUM" -b "$BRANCH" -r "$REPO" || { echo "Failed to execute docker-compose-gen-git.sh."; exit 1; }
./local-docker-env/docker-compose-gen-git.sh -a "$ACCOUNT_NUM" -b "$BRANCH" -r "$REPO" -v "$VERSION" || { echo "Failed to execute docker-compose-gen-git.sh."; exit 1; }

# Dockerfile.boot.git 및 Dockerfile.node.git 파일 복사
cp local-docker-env/Dockerfile.boot.git ./ || { echo "Failed to copy Dockerfile.boot.git."; exit 1; }
Expand Down
20 changes: 11 additions & 9 deletions local-docker-env/local-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
current_dir=$(pwd)
export PATH=$PATH:${current_dir}/go-wemix/build/bin

# 필수 인수 확인
if [ "$#" -ne 2 ]; then
echo "Usage: $0 -a <account_num>"
exit 1
fi

# 옵션 파싱
while getopts "a:" opt; do
while getopts "a:v:" opt; do
case ${opt} in
a)
ACCOUNT_NUM=$OPTARG
;;
v)
VERSION=$OPTARG
;;
\?)
echo "Usage: $0 -a <account_num>"
exit 1
Expand All @@ -25,10 +22,15 @@ done

# 필수 인수 확인
if [ -z "$ACCOUNT_NUM" ]; then
echo "Account number is required."
echo "Account number is required. Usage: $0 -a <account_num>"
exit 1
fi

# Set default version if not provided
if [ -z "$VERSION" ]; then
VERSION="latest"
fi

# key-gen.sh 실행
chmod +x local-docker-env/key-gen.sh
./local-docker-env/key-gen.sh -a "$ACCOUNT_NUM" || { echo "Failed to execute key-gen.sh."; exit 1; }
Expand All @@ -39,7 +41,7 @@ chmod +x local-docker-env/config-gen.sh

# docker-compose-gen.sh 실행
chmod +x local-docker-env/docker-compose-gen.sh
./local-docker-env/docker-compose-gen.sh -a "$ACCOUNT_NUM" || { echo "Failed to execute docker-compose-gen.sh."; exit 1; }
./local-docker-env/docker-compose-gen.sh -a "$ACCOUNT_NUM" -v "$VERSION" || { echo "Failed to execute docker-compose-gen.sh."; exit 1; }

# Dockerfile.boot 및 Dockerfile.node 파일 복사
cp local-docker-env/Dockerfile.boot ./ || { echo "Failed to copy Dockerfile.boot."; exit 1; }
Expand Down

0 comments on commit 35ad901

Please sign in to comment.