Skip to content

Prevent db locking when multiple queries from quay are accessing same tables (PROJQUAY-8758) #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ terraform-key.json
terraform.tfstate*
ansible/context
image-archive.tar
sqlite3.tar
execution-environment.tar
quay-aioi
mirror-registry*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

- name: Load sqlite image if sqlite3.tar exists
shell:
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
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
when: s.stat.exists and local_install == "false"
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,45 @@
name: "{{ sqlite_storage }}"
when: "not sqlite_storage.startswith('/')"

- name: Check if sqlite cli image is loaded
command: podman inspect --type=image {{ sqlite_image }}
register: sqlite_cli
ignore_errors: yes

- name: Fail if sqlite cli image is not found
fail:
msg: "The SQLite CLI image '{{ sqlite_image }}' is not loaded."
when: sqlite_cli.rc != 0

- name: Create quay database file with persistent WAL mode and correct permissions
block:
- name: Create DB file and set permissions with error messages
command: >
podman run --rm
-v {{ expanded_sqlite_storage }}:/sqlite:Z
--entrypoint /bin/sh
{{ sqlite_image }}
-c '
if ! sqlite3 /sqlite/quay_sqlite.db "PRAGMA journal_mode=WAL;"; then
echo "Failed to set WAL mode" >&2
exit 1
fi
if ! chown 1001:1001 /sqlite/quay_sqlite.db; then
echo "Failed to chown database file" >&2
exit 1
fi
if ! chmod 0664 /sqlite/quay_sqlite.db; then
echo "Failed to chmod database file" >&2
exit 1
fi
'
register: db_file_creation_result
failed_when: db_file_creation_result.rc != 0
changed_when: true
retries: 3
delay: 5


- name: Start Quay service
systemd:
name: quay-app.service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- name: Autodetect Image Archive
include_tasks: autodetect-image-archive.yaml

- name: Autodetect Sqlite Archive
include_tasks: autodetect-sqlite-archive.yaml

- name: Install Quay Pod Service
include_tasks: install-pod-service.yaml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pg_to_sqlite() {
" "$input_file"

echo "COMMIT;"
echo "PRAGMA journal_mode=WAL;"
} > "$output_file"

# Validate output file
Expand Down
10 changes: 8 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func install() {
err = loadSSHKeys()
check(err)

var sqliteArchiveMountFlag string
// Load sqlite cli binary
sqliteArchiveMountFlag, err = loadSqliteCli()
check(err)

// Handle Image Archive Defaulting
var imageArchiveMountFlag string
if imageArchivePath == "" {
Expand Down Expand Up @@ -258,6 +263,7 @@ func install() {
`--workdir /runner/project `+
`--net host `+
imageArchiveMountFlag+ // optional image archive flag
sqliteArchiveMountFlag+
sslCertKeyFlag+ // optional ssl cert/key flag
` -v %s:/runner/env/ssh_key `+
`-e RUNNER_OMIT_EVENTS=False `+
Expand All @@ -268,8 +274,8 @@ func install() {
`--quiet `+
`--name ansible_runner_instance `+
fmt.Sprintf("%s ", eeImage)+
`ansible-playbook -i %s@%s, --private-key /runner/env/ssh_key -e "init_user=%s init_password=%s quay_image=%s quay_version=%s redis_image=%s pause_image=%s quay_hostname=%s local_install=%s quay_root=%s quay_storage=%s sqlite_storage=%s quay_cmd=%s" install_mirror_appliance.yml %s %s`,
sshKey, targetUsername, targetHostname, initUser, initPassword, quayImage, quayVersion, redisImage, pauseImage, quayHostname, strconv.FormatBool(isLocalInstall()), quayRoot, quayStorage, sqliteStorage, quayCmd, askBecomePassFlag, additionalArgs)
`ansible-playbook -i %s@%s, --private-key /runner/env/ssh_key -e "init_user=%s init_password=%s quay_image=%s quay_version=%s redis_image=%s sqlite_image=%s pause_image=%s quay_hostname=%s local_install=%s quay_root=%s quay_storage=%s sqlite_storage=%s quay_cmd=%s" install_mirror_appliance.yml %s %s`,
sshKey, targetUsername, targetHostname, initUser, initPassword, quayImage, quayVersion, redisImage, sqliteImage, pauseImage, quayHostname, strconv.FormatBool(isLocalInstall()), quayRoot, quayStorage, sqliteStorage, quayCmd, askBecomePassFlag, additionalArgs)

log.Debug("Running command: " + podmanCmd)
cmd := exec.Command("bash", "-c", podmanCmd)
Expand Down
38 changes: 21 additions & 17 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,28 @@ func loadSqliteCli() (string, error) {
if !pathExists(sqliteArchivePath) {
return "", errors.New("Could not find sqlite3.tar at " + sqliteArchivePath)
}
log.Info("Found sqlite3 cli binary at " + sqliteArchivePath)

sqliteArchiveMountFlag := fmt.Sprintf(" -v %s:/runner/sqlite3.tar", sqliteArchivePath)

if isLocalInstall() {
// Load sqlite3 as a podman image
log.Printf("Loading sqlite3 cli binary from sqlite3.tar")
statement := getImageMetadata("sqlite", sqliteImage, sqliteArchivePath)
sqliteImportCmd := exec.Command("/bin/bash", "-c", statement)
if verbose {
sqliteImportCmd.Stderr = os.Stderr
sqliteImportCmd.Stdout = os.Stdout
}
log.Debug("Importing sqlite3 cli binary with command: ", sqliteImportCmd)
err = sqliteImportCmd.Run()
if err != nil {
return "", err

var sqliteArchiveMountFlag string
if sqliteArchivePath != "" {
sqliteArchiveMountFlag = fmt.Sprintf(" -v %s:/runner/sqlite3.tar", sqliteArchivePath)
log.Info("Found sqlite archive at " + sqliteArchivePath)
if isLocalInstall() {
// Load sqlite3 as a podman image
log.Printf("Loading sqlite3 cli binary from sqlite3.tar")
statement := getImageMetadata("sqlite", sqliteImage, sqliteArchivePath)
sqliteImportCmd := exec.Command("/bin/bash", "-c", statement)
if verbose {
sqliteImportCmd.Stderr = os.Stderr
sqliteImportCmd.Stdout = os.Stdout
}
log.Debug("Importing sqlite3 cli binary with command: ", sqliteImportCmd)
err = sqliteImportCmd.Run()
if err != nil {
return "", err
}
}
}

log.Infof("Attempting to set SELinux rules on sqlite archive")
cmd := exec.Command("chcon", "-Rt", "svirt_sandbox_file_t", sqliteArchivePath)
if verbose {
Expand Down Expand Up @@ -240,6 +243,7 @@ func getImageMetadata(app, imageName, archivePath string) string {
statement = `/usr/bin/podman image import \
--change 'ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' \
--change 'ENV container=oci' \
--change 'USER=1001' \
--change 'ENTRYPOINT=["/usr/bin/sqlite3"]' \
- ` + imageName + ` < ` + archivePath
case "ansible":
Expand Down
Loading