Skip to content

Commit

Permalink
Add a check to fail if sqlite file is not created post db migration +…
Browse files Browse the repository at this point in the history
… code cleanup
  • Loading branch information
harishsurf committed Jun 27, 2024
1 parent ff57778 commit e36b4dd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-22/ansible-build
QUAY_IMAGE=quay.io/projectquay/quay:3.12.0-nightly.20240626
REDIS_IMAGE=registry.redhat.io/rhel8/redis-6:1-92.1669834635
PAUSE_IMAGE=registry.access.redhat.com/ubi8/pause:8.7-6
DB_TO_SQLITE_IMAGE=quay.io/quay/db-to-sqlite:latest
DB_TO_SQLITE_IMAGE=quay.io/quay/db-to-sqlite:latest
6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ ENV PAUSE_IMAGE=${PAUSE_IMAGE}
ENV DB_TO_SQLITE_IMAGE=${DB_TO_SQLITE_IMAGE}

RUN go build -v \
<<<<<<< HEAD
-ldflags "-X github.com/quay/mirror-registry/cmd.releaseVersion=${RELEASE_VERSION} -X github.com/quay/mirror-registry/cmd.eeImage=${EE_IMAGE} -X github.com/quay/mirror-registry/cmd.pauseImage=${PAUSE_IMAGE} -X github.com/quay/mirror-registry/cmd.quayImage=${QUAY_IMAGE} -X github.com/quay/mirror-registry/cmd.redisImage=${REDIS_IMAGE}" \
=======
-ldflags "-X github.com/quay/mirror-registry/cmd.releaseVersion=${RELEASE_VERSION} -X github.com/quay/mirror-registry/cmd.eeImage=${EE_IMAGE} -X github.com/quay/mirror-registry/cmd.pauseImage=${PAUSE_IMAGE} -X github.com/quay/mirror-registry/cmd.quayImage=${QUAY_IMAGE} -X github.com/quay/mirror-registry/cmd.redisImage=${REDIS_IMAGE} -X github.com/quay/mirror-registry/cmd.postgresImage=${POSTGRES_IMAGE} -X github.com/quay/mirror-registry/cmd.sqliteImage=${DB_TO_SQLITE_IMAGE}" \
>>>>>>> 7261fe9 (Add support for sqlite storage in installer binary (PROJQUAY-6286))
-ldflags "-X github.com/quay/mirror-registry/cmd.releaseVersion=${RELEASE_VERSION} -X github.com/quay/mirror-registry/cmd.eeImage=${EE_IMAGE} -X github.com/quay/mirror-registry/cmd.pauseImage=${PAUSE_IMAGE} -X github.com/quay/mirror-registry/cmd.quayImage=${QUAY_IMAGE} -X github.com/quay/mirror-registry/cmd.redisImage=${REDIS_IMAGE} -X github.com/quay/mirror-registry/cmd.sqliteImage=${DB_TO_SQLITE_IMAGE}" \
-o mirror-registry

# Create Ansible Execution Environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
expanded_sqlite_storage: "{{ expanded_sqlite_storage_output.stdout }}"
expanded_quay_root: "{{ expanded_quay_root_output.stdout }}"
expanded_quay_storage: "{{ expanded_quay_storage_output.stdout }}"
expanded_sqlite_storage: "{{ expanded_sqlite_storage_output.stdout }}"
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
state: present
name: redis_pass
data: "{{ redis_password }}"
skip_existing: false
skip_existing: true

- name: Start Redis service
systemd:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,21 @@
command: podman cp quay-db-migration:/data {{ quay_root }}/quay-postgres-backup/
when: container_result.rc == 0

- name: Check if sqlite file exists
stat:
path: "{{ quay_root }}/quay-postgres-backup/quay_sqlite.db"
register: file_check

- fail:
msg: "Sqlite db file '{{ quay_root }}/quay-postgres-backup/quay_sqlite.db' does not exist."
when: file_check.stat.exists == false

- name: Delete temporary migration container
containers.podman.podman_container:
name: quay-db-migration
state: absent
when: container_result.rc == 0

- name: Update DB_URI in config.yaml
replace:
path: "{{ quay_root }}/quay-config/config.yaml"
regexp: '^DB_URI: postgresql://.*$'
replace: 'DB_URI: sqlite:////quay-registry/sqlite/data/quay_sqlite.db'
register: db_uri_update

- debug:
msg: "DB_URI has been updated."
when: db_uri_update.changed

- name: Stop Quay service
systemd:
name: quay-app.service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@
- name: Fail the playbook due to Quay not becoming alive
fail:
msg: "Quay did not become alive. Check debug logs above for details."

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ExecStart=/usr/bin/podman run \
-v {{ expanded_quay_root }}/quay-config:/quay-registry/conf/stack:Z \
-v {{ expanded_sqlite_storage }}:/sqlite:Z \
-v {{ expanded_quay_storage }}:/datastorage:Z \
-v {{ expanded_sqlite_storage }}:/quay-registry/sqlite/data:Z \
--image-volume=ignore \
--pod=quay-pod \
--conmon-pidfile %t/%n-pid \
Expand Down
9 changes: 2 additions & 7 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,8 @@ func upgrade() {
`--quiet `+
`--name ansible_runner_instance `+
fmt.Sprintf("%s ", eeImage)+
<<<<<<< HEAD
`ansible-playbook -i %s@%s, --private-key /runner/env/ssh_key -e "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" upgrade_mirror_appliance.yml %s %s`,
sshKey, targetUsername, targetHostname, quayImage, quayVersion, redisImage, pauseImage, quayHostname, strconv.FormatBool(isLocalInstall()), quayRoot, quayStorage, sqliteStorage, askBecomePassFlag, additionalArgs)
=======
`ansible-playbook -i %s@%s, --private-key /runner/env/ssh_key -e "quay_image=%s quay_version=%s redis_image=%s postgres_image=%s sqlite_image=%s pause_image=%s quay_hostname=%s local_install=%s quay_root=%s quay_storage=%s pg_storage=%s sqlite_storage=%s" upgrade_mirror_appliance.yml %s %s`,
sshKey, targetUsername, targetHostname, quayImage, quayVersion, redisImage, postgresImage, sqliteImage, pauseImage, quayHostname, strconv.FormatBool(isLocalInstall()), quayRoot, quayStorage, pgStorage, sqliteStorage, askBecomePassFlag, additionalArgs)
>>>>>>> d0f8065 (Add ansible tasks to migrate data from postgres to sqlite)
`ansible-playbook -i %s@%s, --private-key /runner/env/ssh_key -e "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" upgrade_mirror_appliance.yml %s %s`,
sshKey, targetUsername, targetHostname, quayImage, quayVersion, redisImage, sqliteImage, pauseImage, quayHostname, strconv.FormatBool(isLocalInstall()), quayRoot, quayStorage, sqliteStorage, askBecomePassFlag, additionalArgs)

log.Debug("Running command: " + podmanCmd)
cmd := exec.Command("bash", "-c", podmanCmd)
Expand Down

0 comments on commit e36b4dd

Please sign in to comment.