Project

General

Profile

Git Workflow » History » Version 3

Redmine Admin, 10/29/2026 08:57 AM
deploy-publish.sh

1 2 Redmine Admin
Repos are bare, owned by the restricted host user `git` (git-shell) — the one
2 1 Redmine Admin
deliberate exception to the no-host-packages rule. Redmine only *reads* them.
3
4
**Who does what — this is the part that causes confusion, so read it first:**
5
6 2 Redmine Admin
| Step                                   | Run as          | Why                                                        |
7
|----------------------------------------|-----------------|------------------------------------------------------------|
8
| create bare repo, ACL, SELinux label   | **root**        | `/srv/git` is root/git territory                           |
9
| `git add` / `git commit` in a working copy | **owner user** (websvcmaster) | keeps `.git/objects` owned by that user          |
10
| commit + push, day to day              | **root**, via `deploy-commit.sh` | it commits *as websvcmaster* and pushes *as root* itself — the only command you normally type |
11
| `git push` by hand                     | **root**        | push needs `sudo -u git git-receive-pack`; websvcmaster has **no sudo** and never will |
12
| register repo in Redmine               | Redmine admin UI |                                                           |
13 1 Redmine Admin
14 2 Redmine Admin
websvcmaster's password is **locked** on purpose (`passwd -l`, set by
15
`01-bootstrap-root.sh`). Enter it only via `su - websvcmaster` from root — never
16
set a password for it. If a command run as websvcmaster asks for a password, it
17
is a root command run in the wrong shell: `exit` to root and run it there.
18 1 Redmine Admin
(`passwd -S websvcmaster` must show `L`.)
19
20 2 Redmine Admin
Repos: `mds-dark.git` (WordPress theme, project "MDS / MIMMAR Web Page Design"),
21 1 Redmine Admin
`dmz-web-deploy.git` (this host's `~/deploy`, project "dmz-web Infrastructure").
22
23
### How Redmine reads them
24
25 2 Redmine Admin
```ini
26 1 Redmine Admin
# site-redmine.container
27
Volume=/srv/git:/srv/git:ro
28
Environment=GIT_CONFIG_COUNT=1
29
Environment=GIT_CONFIG_KEY_0=safe.directory
30
Environment=GIT_CONFIG_VALUE_0=*
31
```
32
33 2 Redmine Admin
Rootless UID mapping: container uid *n* → host uid **200000 + n − 1**; Redmine
34
runs as uid 999 → host **200998** (`podman top site-redmine user huser`).
35 1 Redmine Admin
One-time host prep (root):
36
37 2 Redmine Admin
```bash
38 1 Redmine Admin
semanage fcontext -a -t container_file_t '/srv/git(/.*)?'
39
restorecon -Rv /srv/git
40
```
41
42
### A. New bare repo — root
43
44 2 Redmine Admin
```bash
45 1 Redmine Admin
R=/srv/git/<repo>.git
46
sudo -u git git init --bare $R
47
sudo -u git git -C $R symbolic-ref HEAD refs/heads/main   # bare HEAD defaults to master; every repo here uses main
48
setfacl -R  -m u:200998:rX $R                             # Redmine read access
49
setfacl -R -d -m u:200998:rX $R                           # ...also for files future pushes create
50
restorecon -Rv $R      # "not reset as customized by admin" on every file = already container_file_t = OK
51
git config --global --add safe.directory /home/<user>/<workdir>   # lets root push from that working copy
52
```
53
54
### B. Working copy, first time — owner user (`su - <user>` from root)
55
56 2 Redmine Admin
```bash
57 1 Redmine Admin
git config --global user.name  "<user>"                   # once per user, or commit refuses
58
git config --global user.email "sysadmin@mdsdefense.com"  # matching a Redmine user's email links commits to them
59
cd <workdir>
60
git init -b main
61
# .gitignore first: no *.env, *secret*, *password*, *.key/*.pem/*.crt, dumps, archives, data/, tmp/
62
git add -A && git status --short
63
grep -nEi 'password|secret|token|key_base' -r . --exclude-dir=.git | grep -viE 'Secret=|podman secret|\$\{?[A-Z_]*(PASSWORD|SECRET)'   # must be comments/prompts only
64
git commit -m "initial import $(date +%F)"
65
git remote add origin /srv/git/<repo>.git
66
git log --oneline
67
exit                                                      # back to root
68
```
69
70
### C. Push — root
71
72
First push of a new working copy (once):
73
74 2 Redmine Admin
```bash
75 1 Redmine Admin
cd /home/<user>/<workdir>
76
git push --receive-pack='sudo -u git git-receive-pack' -u origin main
77
chown -R <user>:<user> .git          # root's push leaves root-owned files in .git
78
```
79
80 2 Redmine Admin
Expected: `* [new branch] main -> main`. Verify: `sudo -u git git -C /srv/git/<repo>.git log --oneline`.
81 1 Redmine Admin
After that, never push by hand — use `deploy-commit.sh` (E).
82
83
### D. Redmine
84
85 2 Redmine Admin
Project → Settings → Repositories → New repository: SCM **Git**, Main repository
86
✓, Identifier `<repo>`, Path `/srv/git/<repo>.git`, Report last commit ✓ → Create.
87
Open the Repository tab; the commit must be listed. If not:
88
`podman exec site-redmine git -C /srv/git/<repo>.git log --oneline` —
89 1 Redmine Admin
"dubious ownership" → safe.directory env missing; "permission denied" → ACL (step A).
90
91
### E. Day-to-day — `deploy-commit.sh` (root)
92
93 2 Redmine Admin
One root command does the whole cycle in the right identities: `git add -A`
94
and `git commit` **as websvcmaster** (identity auto-set), a guard that refuses
95
to commit staged lines that look like literal credentials, `git push`
96
**as root** via `sudo -u git git-receive-pack`, optional annotated tag, and
97
`chown` of `.git` back to websvcmaster. Source: `root-bin/deploy-commit.sh` in
98 1 Redmine Admin
the repo; installed as `/usr/local/sbin/deploy-commit.sh` (0750).
99
100 2 Redmine Admin
```bash
101 1 Redmine Admin
deploy-commit.sh -n                         # dry run: shows what is staged, commits nothing
102
deploy-commit.sh -m "what changed"          # commit + push
103
deploy-commit.sh -m "cheat sheet v1.1" -t cheatsheet-1.1   # ...+ tag
104
deploy-commit.sh -t cheatsheet-1.1          # nothing to commit: tag HEAD, push the tag
105
deploy-commit.sh -y -m "..."                # skip the credential guard after checking the flagged lines
106
deploy-commit.sh -h
107
```
108
109 2 Redmine Admin
Editing still happens as websvcmaster (`su - websvcmaster`, edit, `exit`);
110
`deploy-commit.sh` never edits files, only `.git`. The guard flags staged lines of
111
the form `<…password|secret|token|api_key|app_key…> = <literal of 8+ chars>`;
112
variables (`$X`), placeholders (`<…>`, `...`), Quadlet `Secret=` lines and
113
comments are ignored. If it fires: move the value to a Podman secret or
114
`.gitignore` the file and re-run; if the lines are harmless, re-run with `-y`. Install/update the script:
115 1 Redmine Admin
116 2 Redmine Admin
```bash
117
install -o root -g root -m 0750 /home/websvcmaster/deploy/root-bin/deploy-commit.sh /usr/local/sbin/deploy-commit.sh
118
```
119 1 Redmine Admin
120 2 Redmine Admin
### F. Publishing finished work — `deploy-publish.sh` (root)
121 1 Redmine Admin
122 2 Redmine Admin
Replaces the manual "copy from `/root` into the repo, fix owner, commit, tag, type the wiki into
123
Redmine" cycle. A delivery is **one file**, `dmz-web-release-<version>.zip` (`<version>` = the cheat sheet
124
version of that release), dropped into `/root`; run `deploy-publish.sh` as root. It calls
125
`deploy-commit.sh` for the git part, so E still applies.
126 1 Redmine Admin
127 2 Redmine Admin
The package holds the changed files (scripts, the cheat sheet), a `wiki/` folder (pages + png),
128
`RELEASE` (version, build date) and `SHA256SUMS`. What the script does:
129 1 Redmine Admin
130 2 Redmine Admin
0. **Package:** unpacked into a fresh private directory; paths are checked (no `..`, absolute paths
131
   or symlinks), the file name must match `RELEASE`, `SHA256SUMS` must verify, and a file that is not
132
   listed in `SHA256SUMS` rejects the package.
133
1. **Repo:** each known file is compared by its **version header** with the repo / installed copy:
134
   newer → installed (repo files owned by websvcmaster, `/usr/local/sbin` copies root 0750);
135
   identical → nothing to do; **older, same version with different content, or no version header →
136
   refused** (stops a stale copy overwriting a newer one; `-f` overrides). Known files: cheat sheet,
137
   `snipeit-install.sh`, `add-wordpress-site.sh`, `redmine-install.sh`, `check-sites.sh`,
138
   `verify-host-deps.sh`, `deploy-commit.sh`, `deploy-publish.sh` — add a line to the `ITEMS` table in
139
   the script for another one.
140
2. **Commit:** `deploy-commit.sh -m "release <version>: <files and versions>"`; a cheat sheet install also
141
   gets the tag `cheatsheet-<version>` (skipped if that tag exists).
142
3. **Wiki:** `wiki/*.md` → Redmine REST API: page created or updated (parent `Wiki`, the duplicate
143
   `# title` first line dropped, `.png` attached once, unchanged pages skipped). `@@COMMIT@@` in a page
144
   (the Releases table) becomes the commit made in step 2 (on a re-run: the commit of the tag `cheatsheet-<version>`; a page that needs a hash and has none is skipped, never overwritten with the placeholder).
145
4. **Tidy:** after a complete, clean run the package is **moved** (never deleted) to
146
   `/root/deploy-done/<timestamp>/`. With refusals, errors, `-n`, `-R` or `-W` it stays in `/root`; running it
147
   again is safe, handled files then show as *identical* and are skipped.
148 1 Redmine Admin
149 2 Redmine Admin
Loose files (no package) still work: put them into `/root` (and `dmz-web-wiki-pages.zip` for the wiki)
150
and the handled ones are moved to `/root/deploy-done/<timestamp>/`.
151
152
```bash
153
deploy-publish.sh -n          # dry run: the plan, wiki read-only GETs, nothing changed or moved
154
deploy-publish.sh             # do everything with the newest /root/dmz-web-release-*.zip
155
deploy-publish.sh -R          # wiki only            deploy-publish.sh -W   # repo only
156
deploy-publish.sh -m "msg"    # own commit message   deploy-publish.sh -y   # skip deploy-commit's guard
157
deploy-publish.sh -f          # install even when older / equal / no version header
158 1 Redmine Admin
```
159
160 2 Redmine Admin
One-time setup for the wiki step: `deploy-publish.sh --init` writes `/root/.deploy-publish.conf`
161
(mode 0600; set `RM_PROJECT` to the project **identifier**, Project settings → Identifier); put the
162
Redmine API key (My account → API access key) into `/root/.redmine-api-key`, `chmod 600`; Redmine
163
Administration → Settings → API → *Enable REST web service*. Requests go to NPM on this host
164
(`--resolve track.mdsdefense.com:444:127.0.0.1`), like `check-sites.sh`. The page text in Redmine is
165
overwritten by the package's text — the first real run replaces pages that were typed in by hand, so
166
start with `-n`. Bootstrap the first time (the script cannot install itself before it exists):
167 1 Redmine Admin
168 2 Redmine Admin
```bash
169
install -o root -g root -m 0750 /root/deploy-publish.sh /usr/local/sbin/deploy-publish.sh
170
deploy-publish.sh --init && deploy-publish.sh -n
171
```
172 1 Redmine Admin
173 2 Redmine Admin
Afterwards the script updates itself from the package (the running copy is replaced safely).
174 1 Redmine Admin
175 2 Redmine Admin
### Recovering from the usual mistakes
176 1 Redmine Admin
177 2 Redmine Admin
* `fatal: could not open '.git/COMMIT_EDITMSG': Permission denied` (or any
178
  permission error on commit) → root touched `.git` (committed there, or pushed/tagged
179
  without `deploy-commit.sh`). Fix: `chown -R <user>:<user> /home/<user>/<workdir>/.git`,
180
  then use `deploy-commit.sh` from now on (it chowns every time). Also check root's `~/.gitconfig` didn't pick up the user's identity.
181
* `Everything up-to-date` on push right after you expected a new commit → the
182
  commit didn't happen (identity error or permission error scrolled past); `git log --oneline`
183
  and `git status --short` in the working copy. A tag made at that moment points at the
184
  old commit: `deploy-commit.sh -t <tag>` after the real commit (it force-moves the tag).
185
* `error: src refspec main does not match any` → no commit yet on `main` (step B not done).
186
* `error: key does not contain a section: receivepack` → wrong syntax; use
187
  `--receive-pack=` (step C), not `-c receivepack=`.
188
* `sudo: a password is required` / password prompt → you are websvcmaster; this is a root step (`exit`, then `deploy-commit.sh`).
189
* Redmine shows the repo empty → bare HEAD still points to `master` (step A `symbolic-ref`).
190
* `deploy-publish.sh`: `REFUSED: no version header` → the copy is an old/unversioned one; fetch the current file or `-f` if you are sure. `checksum mismatch` / `does not match RELEASE` → the package is damaged or was renamed; get it again. `HTTP 401/403` on the wiki step → API key wrong, REST not enabled, or the account may not edit this project's wiki. `HTTP 404` for every page → wrong `RM_PROJECT` (it must be the identifier, not the project name).
191 1 Redmine Admin
192
---
193 3 Redmine Admin
_Source: `dmz-web-podman-cheatsheet.md` v1.5 in the `dmz-web-deploy` repo ([[Releases]]). Edit the wiki and the repo copy together._