Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
img-manager
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Lan
img-manager
Commits
bc710a02
Commit
bc710a02
authored
Mar 10, 2025
by
Ivan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update deploy
parent
3555e39e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
24 deletions
+46
-24
Dockerfile
Dockerfile
+4
-6
docker-entrypoint
bin/docker-entrypoint
+39
-16
deploy.yml
config/deploy.yml
+3
-2
No files found.
Dockerfile
View file @
bc710a02
# 移除 syntax 指令以避免网络问题
# 原指令: # syntax=docker/dockerfile:1
# syntax=docker/dockerfile:1
# check=error=true
# This Dockerfile is designed for Git-based deployment with Kamal
# It pulls code from Git during deployment and uses external volumes for code, build artifacts, and data
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG
RUBY_VERSION=3.2.2
FROM
docker.io/library/ruby:$RUBY_VERSION-slim
FROM
ruby:3.2.2
# Rails app lives here
WORKDIR
/rails
...
...
@@ -48,11 +46,11 @@ RUN mkdir -p \
/rails/tmp/sockets
# Declare volumes for persistent storage
VOLUME
["/rails/code", "/rails/storage", "/rails/public/uploads", "/rails/public/vite", "/rails/node_modules", "/rails/log", "/rails/tmp"]
VOLUME
["/r
oot/.ssh", "/r
ails/code", "/rails/storage", "/rails/public/uploads", "/rails/public/vite", "/rails/node_modules", "/rails/log", "/rails/tmp"]
# Copy entrypoint script
COPY
bin/docker-entrypoint /rails/bin/
#
RUN chmod +x /rails/bin/docker-entrypoint
RUN
chmod
+x /rails/bin/docker-entrypoint
# Run and own only the runtime files as a non-root user for security
RUN
groupadd
--system
--gid
1000 rails
&&
\
...
...
bin/docker-entrypoint
View file @
bc710a02
...
...
@@ -9,7 +9,9 @@ fi
# Ensure all required directories exist with proper permissions
echo
"Setting up directories..."
echo
"Setting up directories......"
mkdir
-p
/rails/code /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp/pids /rails/tmp/cache /rails/tmp/sockets
echo
"after Setting up directories..."
# Set very permissive permissions for all directories
# chmod -R 777 /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp
...
...
@@ -36,34 +38,55 @@ sleep 5
if
[
-z
"
${
GIT_REPOSITORY
}
"
]
;
then
echo
"⚠️ GIT_REPOSITORY environment variable not set. Using mounted code directory."
else
# 检查代码目录是否已经存在文件
if
[
"
$(
ls
-A
/rails/code 2>/dev/null
)
"
]
;
then
echo
"✅ Code directory is not empty. Using mounted code directory."
echo
"Skipping Git operations to avoid permission issues."
else
echo
"🔄 Setting up code from Git repository:
${
GIT_REPOSITORY
}
"
# Check if we already have the repository
if
[
-d
"/rails/code/.git"
]
;
then
echo
"Git repository exists, pulling latest changes..."
cd
/rails/code
git fetch
# 添加 Git 安全目录配置,解决仓库所有权问题
echo
"Configuring Git safe directory..."
git config
--global
--add
safe.directory /rails/code
# Check if we need to checkout a specific branch or tag
# 检查是否安装了 git 命令
if
!
command
-v
git &> /dev/null
;
then
echo
"⚠️ Git command not found. Skipping Git operations."
else
# 检查是否能访问 Git 仓库
if
git ls-remote
--quiet
${
GIT_REPOSITORY
}
&> /dev/null
;
then
# 尝试克隆仓库,但可能会失败
echo
"Attempting to clone repository (may fail if directory is mounted)..."
if
[
-n
"
${
GIT_BRANCH
}
"
]
;
then
echo
"Checking out branch/tag:
${
GIT_BRANCH
}
"
git checkout
${
GIT_BRANCH
}
git pull origin
${
GIT_BRANCH
}
git clone
--branch
${
GIT_BRANCH
}
${
GIT_REPOSITORY
}
/rails/code
||
echo
"Git clone failed, but continuing anyway"
else
echo
"No branch specified, pulling latest from current branch"
git pull
git clone
${
GIT_REPOSITORY
}
/rails/code
||
echo
"Git clone failed, but continuing anyway"
fi
else
echo
"Cloning repository..."
# Clone the repository
echo
"⚠️ Cannot access Git repository. Skipping Git operations."
fi
fi
fi
# 如果存在 Git 仓库,尝试更新,但不强制
if
[
-d
"/rails/code/.git"
]
;
then
echo
"Git repository exists, attempting to pull latest changes..."
cd
/rails/code
git config
--global
--add
safe.directory /rails/code
git fetch
||
echo
"Git fetch failed, but continuing anyway"
# Check if we need to checkout a specific branch or tag
if
[
-n
"
${
GIT_BRANCH
}
"
]
;
then
git clone
--branch
${
GIT_BRANCH
}
${
GIT_REPOSITORY
}
/rails/code
echo
"Checking out branch/tag:
${
GIT_BRANCH
}
"
git checkout
${
GIT_BRANCH
}
||
echo
"Git checkout failed, but continuing anyway"
git pull origin
${
GIT_BRANCH
}
||
echo
"Git pull failed, but continuing anyway"
else
git clone
${
GIT_REPOSITORY
}
/rails/code
echo
"No branch specified, attempting to pull latest from current branch"
git pull
||
echo
"Git pull failed, but continuing anyway"
fi
fi
echo
"✅
Code updated from Git reposi
tory"
echo
"✅
Using code from mounted direc
tory"
fi
# Create symbolic links from code directory to Rails app directory
...
...
config/deploy.yml
View file @
bc710a02
...
...
@@ -10,7 +10,7 @@ servers:
hosts
:
-
45.78.59.154
labels
:
traefik.http.routers.app.rule
:
Host(`img.mumumumushu.com`)
traefik.http.routers.app.rule
:
Host(`img
-manager
.mumumumushu.com`)
# job:
# hosts:
# - 192.168.0.1
...
...
@@ -44,7 +44,7 @@ env:
# - GIT_CREDENTIALS
clear
:
# Git repository configuration
GIT_REPOSITORY
:
http://git.tallty.com/
mumumumushu/img-manager.git
GIT_REPOSITORY
:
git@git.tallty.com:
mumumumushu/img-manager.git
GIT_BRANCH
:
main
# Force rebuild flags (set to true when you want to force rebuild)
...
...
@@ -101,6 +101,7 @@ volumes:
-
"
/root/img_manager/logs:/rails/log"
# Tmp directory for pids and other temporary files
-
"
/root/img_manager/tmp:/rails/tmp"
-
"
/root/.ssh:/root/.ssh"
# Bridge fingerprinted assets, like JS and CSS, between versions to avoid
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment