Winse Blog

走走停停都是风景, 熙熙攘攘都向最好, 忙忙碌碌都为明朝, 何畏之.

Reinstall Redmine on Raspberry2

年前把树莓派拯救了回来 重新折腾raspberry2 由于年底了新平台慢慢成型,可能会用到BUG跟踪,想着不能浪费,能用则用能省者省的原则,把老古董用起来。

原来在树莓派2上安装过redmine的 在树莓派上部署redmine 不过有些年头了,一开始想着刻舟求剑的方法能参照绝不死脑细胞的原则,现实则是四处碰壁。

这个配置确实有点拿不出手了。

1
2
3
4
5
6
7
8
top - 14:01:28 up 1 min,  1 user,  load average: 1.87, 0.63, 0.22
Tasks: 130 total,   1 running, 129 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.0 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :  0.3 us,  0.3 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :    922.0 total,    643.8 free,     79.7 used,    198.5 buff/cache
MiB Swap:    100.0 total,    100.0 free,      0.0 used.    788.3 avail Mem 

参照学习

原来老版本安装的是 postgres9.6 + redmine3.4 的版本,2020年的时刻这些版本都还当时热乎着的,当时也用上了原来的数据以及插件都还想和原来一样使用。现在再来安装这个版本已经时过境迁了,官方的postgres9.6已经归档了。

1、ubuntu-14官方不支持以后,postgresql官网和各种镜像的网站的都没有该版本的9.6的源码。

2、找一个相对旧一些的操作系统ubuntu-20(focal)支持postgres9.6的,然后试着按原来源码编译的方式打包postgres-9.6 armv7的版本。

安装编译的依赖,编译打包除了慢一点(一个通宵)看起来都通过了(中间过程漫长有冗长没细细的看)。

打包好deb,等安装的时刻,就出现依赖不对找不到了。齐了怪了,编译都“通过”了,安装就不行,perl缺的依赖又找不到对应的版本。又重新弄了两遍!!!这个时间和精神消耗,我这身子骨已经跟它耗不起了。改变方式。

3、docker postgres有镜像也是11之后的,更别说是armv7的9.6了。

4、经过几天的折腾,狠狠心咬咬牙,换最新版本。只能最后再迁移数据,这样估计快一点。

实践与改进

确定使用最新的版本后,找到 sameersbn/redmine:5.10 然后用的是postgres-15数据库。在上面折腾的过程中,已经找过armv7的postgres数据库了,这次直接基于官方armv7-postgres-15作为基础来构建我这个应用数据库的镜像。

postgres

编译 armv7-postgres15 除了在LANG上有一些些错之外,其他都是挺顺利的。修改的内容以及Dockerfile内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
root@raspberrypi:/opt/docker-postgresql-15-20230628# vim runtime/functions 

300         if [[ -z $(psql -U ${PG_USER} -Atc "SELECT 1 FROM pg_catalog.pg_user WHERE usename = '${DB_USER}'";) ]]; then
301           #psql -U ${PG_USER} -c "CREATE ROLE \"${DB_USER}\" with LOGIN CREATEDB PASSWORD '${DB_PASS}';" >/dev/null
302           psql -U ${PG_USER} -c "CREATE ROLE \"${DB_USER}\" SUPERUSER CREATEDB CREATEROLE LOGIN PASSWORD '${DB_PASS}';" >/dev/null
303         fi

root@raspberrypi:/opt/docker-postgresql-15-20230628# cat Dockerfile 
FROM arm32v7/postgres:15-bullseye

LABEL maintainer="sameer@damagehead.com"

ENV LC_ALL="en_US.UTF-8" \
    LC_CTYPE="en_US.UTF-8"

ENV PG_APP_HOME="/etc/docker-postgresql" \
    PG_VERSION=15 \
    PG_USER=postgres \
    PG_HOME=/var/lib/postgresql \
    PG_RUNDIR=/run/postgresql \
    PG_LOGDIR=/var/log/postgresql \
    PG_CERTDIR=/etc/postgresql/certs

ENV PG_BINDIR=/usr/lib/postgresql/${PG_VERSION}/bin \
    PG_DATADIR=${PG_HOME}/${PG_VERSION}/main

RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
RUN echo "LANG=en_US.UTF-8" > /etc/locale.conf

RUN sed -i 's@http://deb.debian.org@http://mirrors.aliyun.com@g' /etc/apt/sources.list \
 && apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y acl sudo locales \
 && update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \
 && locale-gen en_US.UTF-8 \
 && DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales \
 && mkdir -p /etc/postgresql/${PG_VERSION}/main \
 && ln -sf ${PG_DATADIR}/postgresql.conf /etc/postgresql/${PG_VERSION}/main/postgresql.conf \
 && ln -sf ${PG_DATADIR}/pg_hba.conf /etc/postgresql/${PG_VERSION}/main/pg_hba.conf \
 && ln -sf ${PG_DATADIR}/pg_ident.conf /etc/postgresql/${PG_VERSION}/main/pg_ident.conf \
 && rm -rf ${PG_HOME} \
 && rm -rf /var/lib/apt/lists/*

COPY runtime/ ${PG_APP_HOME}/

COPY entrypoint.sh /sbin/entrypoint.sh

RUN chmod 755 /sbin/entrypoint.sh

EXPOSE 5432/tcp

WORKDIR ${PG_HOME}

ENTRYPOINT ["/sbin/entrypoint.sh"]

redmine

再编译redmine,这个构建镜像的时刻下载依赖太慢了,可能是安装的这些软件对树莓派2要求有点过高了,多次没响应远程断掉导致要重新弄。用了screen也没有效果。

  1. 开一个screen的窗口,再启动一个容器。
  2. 在容器里面手动安装先把依赖搞定后,最后把容器提交作为一个镜像。
  3. 在这个镜像的基础上再构建redmine应用的镜像。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
root@raspberrypi:~/docker-redmine-5.1.0# docker run -ti arm32v7/ruby:2.7.8-bullseye bash 

root@e76bef6f1a9c:/# 
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - 
echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main' > /etc/apt/sources.list.d/pgdg.list 

sed -i 's@http://deb.debian.org@https://mirrors.aliyun.com@g' /etc/apt/sources.list && apt-get update
#sed -i 's@http://deb.debian.org@https://mirrors.ustc.edu.cn@g' /etc/apt/sources.list && apt-get update


# 去掉mysql和ruby依赖
apt-get install --no-install-recommends -y \
      supervisor logrotate nginx postgresql-client ca-certificates sudo tzdata \
      imagemagick subversion git cvs bzr mercurial darcs rsync locales openssh-client \
      gcc g++ make patch pkg-config gettext-base libc6-dev zlib1g-dev libxml2-dev \
      libpq5 libyaml-0-2 libcurl4 libssl1.1 uuid-dev xz-utils \
      libxslt1.1 libffi7 zlib1g gsfonts vim-tiny ghostscript sqlite3 libsqlite3-dev 
  
update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX

gem install --no-document bundler


# 修改redmine的安装脚本
# @see https://mirrors.tuna.tsinghua.edu.cn/help/rubygems/
root@raspberrypi:/opt/docker-redmine-5.1.0# vi assets/build/install.sh 
  7 BUILD_DEPENDENCIES="wget libcurl4-openssl-dev libssl-dev libmagickcore-dev libmagickwand-dev \
  8                     libpq-dev libxslt1-dev libffi-dev libyaml-dev \
  9                     libsqlite3-dev"

 41   exec_as_redmine wget --no-check-certificate "http://www.redmine.org/releases/redmine-${REDMINE_VERSION}.tar.gz" -O /tmp/redmine-${RE    DMINE_VERSION}.tar.gz
 
104 exec_as_redmine gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
105 exec_as_redmine bundle config mirror.https://rubygems.org https://mirrors.tuna.tsinghua.edu.cn/rubygems
106 exec_as_redmine bundle install -j$(nproc)

# 拷贝到容器安装redmine
root@raspberrypi:~/docker-redmine-5.1.0# docker cp assets/build/install.sh  e76bef6f1a9c:/opt/


root@e76bef6f1a9c:/# cd /opt/
export RUBY_VERSION=2.7 \
   REDMINE_VERSION=5.1.0 \
   REDMINE_USER="redmine" \
   REDMINE_HOME="/home/redmine" \
   REDMINE_LOG_DIR="/var/log/redmine" \
   REDMINE_ASSETS_DIR="/etc/docker-redmine" \
   RAILS_ENV=production

export REDMINE_INSTALL_DIR="${REDMINE_HOME}/redmine" \
   REDMINE_DATA_DIR="${REDMINE_HOME}/data" \
   REDMINE_BUILD_ASSETS_DIR="${REDMINE_ASSETS_DIR}/build" \
   REDMINE_RUNTIME_ASSETS_DIR="${REDMINE_ASSETS_DIR}/runtime"

root@e76bef6f1a9c:/# bash -x install.sh


# 安装好后,停掉容器提交作为镜像
root@raspberrypi:~/docker-redmine-5.1.0# docker stop e76bef6f1a9c
root@raspberrypi:~/docker-redmine-5.1.0# docker commit e76bef6f1a9c arm32v7/ruby:2.7.8-bullseye-redmine-base

root@raspberrypi:/opt/docker-redmine-5.1.0# cat Dockerfile 
#FROM arm32v7/ruby:2.7.8-bullseye AS add-apt-repositories
#
#RUN sed -i 's@http://deb.debian.org@https://mirrors.aliyun.com@g' /etc/apt/sources.list \
# && apt-get update \
# && DEBIAN_FRONTEND=noninteractive apt-get install -y wget gnupg2 \
# && apt-key adv --keyserver keyserver.ubuntu.com --recv E1DD270288B4E6030699E45FA1715D88E1DF1F24 \
# && apt-key adv --keyserver keyserver.ubuntu.com --recv 80F70E11F0F0D5F10CB20E62F5DA5F09C3173AA6 \
# && apt-key adv --keyserver keyserver.ubuntu.com --recv 8B3981E7A6852F782CC4951600A6F0A3C300EE8C \
# && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
# && echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main' > /etc/apt/sources.list.d/pgdg.list 

FROM arm32v7/ruby:2.7.8-bullseye-redmine-base

LABEL maintainer="sameer@damagehead.com"

ENV RUBY_VERSION=2.7 \
    REDMINE_VERSION=5.1.0 \
    REDMINE_USER="redmine" \
    REDMINE_HOME="/home/redmine" \
    REDMINE_LOG_DIR="/var/log/redmine" \
    REDMINE_ASSETS_DIR="/etc/docker-redmine" \
    RAILS_ENV=production

ENV REDMINE_INSTALL_DIR="${REDMINE_HOME}/redmine" \
    REDMINE_DATA_DIR="${REDMINE_HOME}/data" \
    REDMINE_BUILD_ASSETS_DIR="${REDMINE_ASSETS_DIR}/build" \
    REDMINE_RUNTIME_ASSETS_DIR="${REDMINE_ASSETS_DIR}/runtime"

#COPY --from=add-apt-repositories /etc/apt/trusted.gpg /etc/apt/trusted.gpg
#
#COPY --from=add-apt-repositories /etc/apt/sources.list /etc/apt/sources.list
#COPY --from=add-apt-repositories /etc/apt/sources.list.d/pgdg.list /etc/apt/sources.list.d/
#
#RUN sed -i 's@http://deb.debian.org@https://mirrors.aliyun.com@g' /etc/apt/sources.list \
# && apt-get update \
# && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
#      supervisor logrotate nginx postgresql-client ca-certificates sudo tzdata \
#      imagemagick subversion git cvs rsync locales openssh-client \
#      gcc g++ make patch pkg-config gettext-base libxml2-dev \
#      python3-pil python3-scour libimage-exiftool-perl ffmpegthumbnailer \
#      libpq5 libyaml-0-2 libcurl4 libssl1.1 uuid-dev xz-utils \
#      libxslt1.1 vim-tiny sqlite3 libsqlite3-dev \
# && update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \
# && gem install --no-document bundler \
# && rm -rf /var/lib/apt/lists/*

#COPY assets/build/ ${REDMINE_BUILD_ASSETS_DIR}/
#
#RUN bash ${REDMINE_BUILD_ASSETS_DIR}/install.sh

COPY assets/runtime/ ${REDMINE_RUNTIME_ASSETS_DIR}/

COPY assets/tools/ /usr/bin/

COPY entrypoint.sh /sbin/entrypoint.sh

COPY VERSION /VERSION

RUN chmod 755 /sbin/entrypoint.sh \
 && sed -i '/session    required     pam_loginuid.so/c\#session    required   pam_loginuid.so' /etc/pam.d/cron

EXPOSE 80/tcp 443/tcp

WORKDIR ${REDMINE_INSTALL_DIR}

ENTRYPOINT ["/sbin/entrypoint.sh"]

CMD ["app:start"]

root@raspberrypi:/opt/docker-redmine-5.1.0# make build

root@raspberrypi:/opt/docker-redmine-5.1.0# docker images 
REPOSITORY             TAG                           IMAGE ID       CREATED        SIZE
sameersbn/postgresql   15-20230628                   cedece0ace69   1 hours ago   324MB
sameersbn/redmine      latest                        f1ab03480a1e   1 hours ago   953MB
arm32v7/ruby           2.7.8-bullseye-redmine-base   3ee3b95c4c85   1 hours ago   953MB
arm32v7/postgres       15-bullseye                   c8e0db9da7af   8 days ago     314MB
arm32v7/ruby           2.7.8-bullseye                8100b7e215f8   6 months ago   667MB

redmine-3.4的数据迁移到redmine-5.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
root@1cd14c92899a:/var/lib/postgresql# docker ps 
CONTAINER ID   IMAGE                        COMMAND                  CREATED        STATUS      PORTS                                 NAMES
458df7209e1b   sameersbn/redmine:3.4.6      "/sbin/entrypoint.sh…"   6 months ago   Up 2 days   443/tcp, 172.21.37.204:8081->80/tcp   redmine_redmine_1
884a04c9f985   sameersbn/postgresql:9.6-2   "/sbin/entrypoint.sh"    2 years ago    Up 2 days   5432/tcp                              redmine_postgresql_1

root@1cd14c92899a:/var/lib/postgresql# pg_dump -U postgres -Cc -d redmine_production >redmine.dump 


# 把redmine-5.1的也导出来一份对照,把库里已有的数据保留,在旧sql里面去掉5存在的记录(不然导入报逐渐冲突导入失败的)。

# 配置数据导入,增加旧版本需要的字段。
ALTER TABLE projects
  ADD COLUMN customers_deploys_notifications_emails character varying,
  ADD COLUMN deploys_notifications_emails character varying,
  ADD COLUMN abbreviation character varying
  ;

ALTER TABLE trackers
  ADD COLUMN is_in_chlog boolean DEFAULT false NOT NULL
  ;

ALTER TABLE users
  ADD COLUMN identity_url character varying
  ;

删掉空的表和数据还原部分。把需要的,保留有数据的表。

数据库备份处理不好要重新做的话,要删除对应的文件内容,然后重启即可。

1
2
3
4
root@raspberrypi:~/docker-redmine-5.1.0# docker-compose down 
root@raspberrypi:~/docker-redmine-5.1.0# rm -rf /srv/docker/redmine

root@raspberrypi:~/docker-redmine-5.1.0# docker-compose up 

图片附件解压文件

1
root@raspberrypi:/# tar zxvf srv-docker-redmine.tar.gz /srv/docker/redmine/redmine/files 

redmine插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
root@raspberrypi:/srv/docker/redmine/redmine/plugins# unzip clipboard_image_paste-1.13.zip 
root@raspberrypi:/srv/docker/redmine/redmine/plugins# mv clipboard_image_paste-1.13 clipboard_image_paste
root@raspberrypi:/srv/docker/redmine/redmine/plugins# rm clipboard_image_paste-1.13.zip 
root@raspberrypi:~/docker-redmine-5.1.0# docker-compose up -d 


root@raspberrypi:/srv/docker/redmine/redmine/plugins# less clipboard_image_paste/init.rb
 30 # @see https://github.com/paginagmbh/redmine_lightbox2/blob/master/init.rb
 31 if Rails::VERSION::MAJOR >= 5
 32   ActiveSupport::Reloader.to_prepare do
 33     require_dependency 'clipboard_image_paste/hooks'
 34     require_dependency 'clipboard_image_paste/attachment_patch'
 35   end 
 36 elsif Rails::VERSION::MAJOR >= 3

# @see https://github.com/peclik/clipboard_image_paste/pull/91/commits/570acebeb5dded80f24e7b01ffddbec09c9eccb6
root@raspberrypi:/srv/docker/redmine/redmine/plugins# less clipboard_image_paste/lib/clipboard_image_paste/attachment_patch.rb
 25       #alias_method_chain :save_attachments, :pasted_images
 26       alias_method :save_attachmenets_without_pasted_images, :save_attachments
 27       alias_method :save_attachments, :save_attachments_with_pasted_images
 
root@raspberrypi:~/docker-redmine-5.1.0# docker-compose restart redmine 


lightbox2
https://github.com/theforeman/redmine_lightbox2/commit/9c8b41f6893d4a92bb30923684bad7a1b40fdb62

apijs
https://www.luigifab.fr/en/redmine/apijs.php

pi@raspberrypi:/srv/docker/redmine/redmine-logs $ docker logs -n 50 1e966fec7f9b

docker-compose

1
2
3
# @see https://github.com/docker/compose/releases/

root@raspberrypi:/usr/local/bin# ln -s docker-compose-linux-armv7 docker-compose

反思与深思

搞搞简单的文字还行,图片大了要计算的话就卡了!!!还是用4吧!!!

pi4上安装简单多了,直接在机器上编译一下镜像就可以了:

  1. postgres的用户修改下权限;
  2. redmine去掉mysql的依赖。
1
2
3
4
5
6
7
8

#@ pi2
root@1cd14c92899a:/var/lib/postgresql# pg_dump -U redmine -Cc -d redmine_production >redmine.dump        

#@ pi4
root@d744a148ea59:/var/lib/postgresql# psql -U redmine -d postgres -f redmine.dump 

# srv的话,只需要复制redmine下的files、plugins。

–END

Comments