Skip to content

Commit 04ce34c

Browse files
committed
Add error handling + fix permissions
1 parent 4bd41a7 commit 04ce34c

File tree

4 files changed

+47
-26
lines changed

4 files changed

+47
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ terraform-key.json
66
terraform.tfstate*
77
ansible/context
88
image-archive.tar
9+
sqlite3.tar
910
execution-environment.tar
1011
quay-aioi
1112
mirror-registry*

ansible-runner/context/app/project/roles/mirror_appliance/tasks/autodetect-sqlite-archive.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
- name: Load sqlite image if sqlite3.tar exists
1212
shell:
13-
cmd: podman image import --change 'ENV PATH=/opt/app-root/src/bin:/opt/app-root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' --change 'ENV container=oci' --change 'ENTRYPOINT=["/usr/bin/sqlite3"]' - {{ sqlite_image }} < {{ quay_root }}/sqlite3.tar
13+
cmd: podman image import --change 'ENV PATH=/opt/app-root/src/bin:/opt/app-root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' --change 'ENV container=oci' --change 'USER=1001' --change 'ENTRYPOINT=["/usr/bin/sqlite3"]' - {{ sqlite_image }} < {{ quay_root }}/sqlite3.tar
1414
when: s.stat.exists and local_install == "false"

ansible-runner/context/app/project/roles/mirror_appliance/tasks/install-quay-service.yaml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,32 @@
159159

160160
- name: Create quay database file with persistent WAL mode and correct permissions
161161
block:
162-
- name: Create sqlite file in WAL mode
162+
- name: Create DB file and set permissions with error messages
163163
command: >
164-
podman run --rm -v {{ expanded_sqlite_storage }}:/sqlite:Z --name sqlite-cli
165-
{{ sqlite_image }} /sqlite/quay_sqlite.db -cmd "PRAGMA journal_mode=WAL;"
164+
podman run --rm
165+
-v {{ expanded_sqlite_storage }}:/sqlite:Z
166+
--entrypoint /bin/sh
167+
{{ sqlite_image }}
168+
-c '
169+
if ! sqlite3 /sqlite/quay_sqlite.db "PRAGMA journal_mode=WAL;"; then
170+
echo "Failed to set WAL mode" >&2
171+
exit 1
172+
fi
173+
if ! chown 1001:1001 /sqlite/quay_sqlite.db; then
174+
echo "Failed to chown database file" >&2
175+
exit 1
176+
fi
177+
if ! chmod 0664 /sqlite/quay_sqlite.db; then
178+
echo "Failed to chmod database file" >&2
179+
exit 1
180+
fi
181+
'
182+
register: db_file_creation_result
183+
failed_when: db_file_creation_result.rc != 0
184+
changed_when: true
185+
retries: 3
186+
delay: 5
166187

167-
- name: Set permissions for the sqlite file
168-
file:
169-
path: "{{ expanded_sqlite_storage }}/quay_sqlite.db"
170-
mode: u=rw,g=rw,o=r
171-
when: "sqlite_storage.startswith('/')"
172188

173189
- name: Start Quay service
174190
systemd:

cmd/utils.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,25 +193,28 @@ func loadSqliteCli() (string, error) {
193193
if !pathExists(sqliteArchivePath) {
194194
return "", errors.New("Could not find sqlite3.tar at " + sqliteArchivePath)
195195
}
196-
log.Info("Found sqlite3 cli binary at " + sqliteArchivePath)
197-
198-
sqliteArchiveMountFlag := fmt.Sprintf(" -v %s:/runner/sqlite3.tar", sqliteArchivePath)
199-
200-
if isLocalInstall() {
201-
// Load sqlite3 as a podman image
202-
log.Printf("Loading sqlite3 cli binary from sqlite3.tar")
203-
statement := getImageMetadata("sqlite", sqliteImage, sqliteArchivePath)
204-
sqliteImportCmd := exec.Command("/bin/bash", "-c", statement)
205-
if verbose {
206-
sqliteImportCmd.Stderr = os.Stderr
207-
sqliteImportCmd.Stdout = os.Stdout
208-
}
209-
log.Debug("Importing sqlite3 cli binary with command: ", sqliteImportCmd)
210-
err = sqliteImportCmd.Run()
211-
if err != nil {
212-
return "", err
196+
197+
var sqliteArchiveMountFlag string
198+
if sqliteArchivePath != "" {
199+
sqliteArchiveMountFlag = fmt.Sprintf(" -v %s:/runner/sqlite3.tar", sqliteArchivePath)
200+
log.Info("Found sqlite archive at " + sqliteArchivePath)
201+
if isLocalInstall() {
202+
// Load sqlite3 as a podman image
203+
log.Printf("Loading sqlite3 cli binary from sqlite3.tar")
204+
statement := getImageMetadata("sqlite", sqliteImage, sqliteArchivePath)
205+
sqliteImportCmd := exec.Command("/bin/bash", "-c", statement)
206+
if verbose {
207+
sqliteImportCmd.Stderr = os.Stderr
208+
sqliteImportCmd.Stdout = os.Stdout
209+
}
210+
log.Debug("Importing sqlite3 cli binary with command: ", sqliteImportCmd)
211+
err = sqliteImportCmd.Run()
212+
if err != nil {
213+
return "", err
214+
}
213215
}
214216
}
217+
215218
log.Infof("Attempting to set SELinux rules on sqlite archive")
216219
cmd := exec.Command("chcon", "-Rt", "svirt_sandbox_file_t", sqliteArchivePath)
217220
if verbose {
@@ -240,6 +243,7 @@ func getImageMetadata(app, imageName, archivePath string) string {
240243
statement = `/usr/bin/podman image import \
241244
--change 'ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' \
242245
--change 'ENV container=oci' \
246+
--change 'USER=1001' \
243247
--change 'ENTRYPOINT=["/usr/bin/sqlite3"]' \
244248
- ` + imageName + ` < ` + archivePath
245249
case "ansible":

0 commit comments

Comments
 (0)