Skip to content

Commit

Permalink
Add upgrade command (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
HammerMeetNail authored Mar 7, 2022
1 parent 740ec65 commit b7f8aca
Show file tree
Hide file tree
Showing 20 changed files with 403 additions and 33 deletions.
9 changes: 6 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
EE_IMAGE=quay.io/quay/mirror-registry-ee:latest
POSTGRES_IMAGE=registry.redhat.io/rhel8/postgresql-10:1-161 as postgres
QUAY_IMAGE=registry.redhat.io/quay/quay-rhel8:v3.6.1
EE_BASE_IMAGE=registry.redhat.io/ansible-automation-platform-20-early-access/ee-minimal-rhel8
EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-20-early-access/ansible-builder-rhel8:2.0.0-15
POSTGRES_IMAGE=registry.redhat.io/rhel8/postgresql-10:1-161
QUAY_IMAGE=registry.redhat.io/quay/quay-rhel8:v3.6.4
REDIS_IMAGE=registry.redhat.io/rhel8/redis-6:1-25
RELEASE_VERSION=v1.0.0
RELEASE_VERSION=v1.1.0
PAUSE_IMAGE=registry.access.redhat.com/ubi8/pause:latest
28 changes: 20 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
ARG EE_BASE_IMAGE=registry.redhat.io/ansible-automation-platform-20-early-access/ee-minimal-rhel8
ARG EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-20-early-access/ansible-builder-rhel8:2.0.0-15
ARG QUAY_IMAGE=${QUAY_IMAGE}
ARG EE_IMAGE=${EE_IMAGE}
ARG EE_BASE_IMAGE=${EE_BASE_IMAGE}
ARG EE_BUILDER_IMAGE=${EE_BUILDER_IMAGE}
ARG POSTGRES_IMAGE=${POSTGRES_IMAGE}
ARG REDIS_IMAGE=${REDIS_IMAGE}
ARG PAUSE_IMAGE=${PAUSE_IMAGE}

# Create Go CLI
FROM registry.redhat.io/ubi8:latest AS cli

# Need to duplicate these, otherwise they won't be available to the stage
ARG QUAY_IMAGE=${QUAY_IMAGE}
ARG EE_IMAGE=${EE_IMAGE}
ARG POSTGRES_IMAGE=${POSTGRES_IMAGE}
ARG REDIS_IMAGE=${REDIS_IMAGE}
ARG PAUSE_IMAGE=${PAUSE_IMAGE}

ENV GOROOT=/usr/local/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Expand All @@ -16,11 +28,11 @@ COPY . /cli
WORKDIR /cli

# Create CLI
ENV EE_IMAGE=quay.io/quay/mirror-registry-ee:latest
ENV QUAY_IMAGE=registry.redhat.io/quay/quay-rhel8:v3.6.1
ENV REDIS_IMAGE=registry.redhat.io/rhel8/redis-6:1-25
ENV POSTGRES_IMAGE=registry.redhat.io/rhel8/postgresql-10:1-161
ENV PAUSE_IMAGE=registry.access.redhat.com/ubi8/pause:latest
ENV EE_IMAGE=${EE_IMAGE}
ENV QUAY_IMAGE=${QUAY_IMAGE}
ENV REDIS_IMAGE=${REDIS_IMAGE}
ENV POSTGRES_IMAGE=${POSTGRES_IMAGE}
ENV PAUSE_IMAGE=${PAUSE_IMAGE}

RUN go build -v \
-ldflags "-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}" \
Expand Down Expand Up @@ -54,7 +66,7 @@ RUN /output/install-from-bindep && rm -rf /output/wheels
COPY ansible-runner/context/app /runner

# Pull in Quay dependencies
FROM registry.redhat.io/quay/quay-rhel8:v3.6.1 as quay
FROM registry.redhat.io/quay/quay-rhel8:v3.6.2 as quay
FROM registry.redhat.io/rhel8/redis-6:1-25 as redis
FROM registry.redhat.io/rhel8/postgresql-10:1-161 as postgres
FROM registry.access.redhat.com/ubi8/pause:latest as pause
Expand Down
21 changes: 14 additions & 7 deletions Dockerfile.online
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
ARG EE_BASE_IMAGE=registry.redhat.io/ansible-automation-platform-20-early-access/ee-minimal-rhel8
ARG EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-20-early-access/ansible-builder-rhel8:2.0.0-15
ARG EE_BASE_IMAGE=${EE_BASE_IMAGE}
ARG EE_BUILDER_IMAGE=${EE_BUILDER_IMAGE}

# Create Go CLI
FROM registry.redhat.io/ubi8:latest AS cli

# Need to duplicate these, otherwise they won't be available to the stage
ARG QUAY_IMAGE=${QUAY_IMAGE}
ARG EE_IMAGE=${EE_IMAGE}
ARG POSTGRES_IMAGE=${POSTGRES_IMAGE}
ARG REDIS_IMAGE=${REDIS_IMAGE}
ARG PAUSE_IMAGE=${PAUSE_IMAGE}

ENV GOROOT=/usr/local/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Expand All @@ -16,11 +23,11 @@ COPY . /cli
WORKDIR /cli

# Create CLI
ENV EE_IMAGE=quay.io/quay/mirror-registry-ee:latest
ENV QUAY_IMAGE=registry.redhat.io/quay/quay-rhel8:v3.6.1
ENV REDIS_IMAGE=registry.redhat.io/rhel8/redis-6:1-25
ENV POSTGRES_IMAGE=registry.redhat.io/rhel8/postgresql-10:1-161
ENV PAUSE_IMAGE=registry.access.redhat.com/ubi8/pause:latest
ENV EE_IMAGE=${EE_IMAGE}
ENV QUAY_IMAGE=${QUAY_IMAGE}
ENV REDIS_IMAGE=${REDIS_IMAGE}
ENV POSTGRES_IMAGE=${POSTGRES_IMAGE}
ENV PAUSE_IMAGE=${PAUSE_IMAGE}

RUN go build -v \
-ldflags "-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}" \
Expand Down
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@ build-golang-executable:
-o mirror-registry;

build-online-zip:
sudo podman build -t mirror-registry-online:${RELEASE_VERSION} --file Dockerfile.online .
sudo podman build \
-t mirror-registry-online:${RELEASE_VERSION} \
--build-arg QUAY_IMAGE=${QUAY_IMAGE} \
--build-arg EE_IMAGE=${EE_IMAGE} \
--build-arg EE_BASE_IMAGE=${EE_BASE_IMAGE} \
--build-arg EE_BUILDER_IMAGE=${EE_BUILDER_IMAGE} \
--build-arg POSTGRES_IMAGE=${POSTGRES_IMAGE} \
--build-arg REDIS_IMAGE=${REDIS_IMAGE} \
--build-arg PAUSE_IMAGE=${PAUSE_IMAGE} \
--file Dockerfile.online .
sudo podman run --name mirror-registry-online-${RELEASE_VERSION} mirror-registry-online:${RELEASE_VERSION}
sudo podman cp mirror-registry-online-${RELEASE_VERSION}:/mirror-registry.tar.gz .

build-offline-zip:
sudo podman build -t mirror-registry-offline:${RELEASE_VERSION} --file Dockerfile .
sudo podman build \
-t mirror-registry-offline:${RELEASE_VERSION} \
--build-arg QUAY_IMAGE=${QUAY_IMAGE} \
--build-arg EE_IMAGE=${EE_IMAGE} \
--build-arg EE_BASE_IMAGE=${EE_BASE_IMAGE} \
--build-arg EE_BUILDER_IMAGE=${EE_BUILDER_IMAGE} \
--build-arg POSTGRES_IMAGE=${POSTGRES_IMAGE} \
--build-arg REDIS_IMAGE=${REDIS_IMAGE} \
--build-arg PAUSE_IMAGE=${PAUSE_IMAGE} \
--file Dockerfile .
sudo podman run --name mirror-registry-offline-${RELEASE_VERSION} mirror-registry-offline:${RELEASE_VERSION}
sudo podman cp mirror-registry-offline-${RELEASE_VERSION}:/mirror-registry.tar.gz .

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
---
redis_image: "registry.redhat.io/rhel8/redis-6:1-25"
postgres_image: "registry.redhat.io/rhel8/postgresql-10:1-161"
quay_image: "registry.redhat.io/quay/quay-rhel8:v3.6.1"
pause_image: "registry.access.redhat.com/ubi8/pause:latest"
quay_hostname: "quay:8443"
quay_root: "/etc/quay-install"
auto_approve: "false"
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
name: quay-pod.service
enabled: yes
daemon_reload: yes
state: started
state: restarted
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
name: quay-postgres.service
enabled: yes
daemon_reload: yes
state: started
state: restarted

- name: Wait for pg_trgm to be installed
command: podman exec -it quay-postgres /bin/bash -c "echo 'CREATE EXTENSION IF NOT EXISTS pg_trgm' | psql -d quay -U postgres"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@
name: quay-app.service
enabled: yes
daemon_reload: yes
state: started
state: restarted
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
name: quay-redis.service
enabled: yes
daemon_reload: yes
state: started
state: restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- name: Copy Quay Pod systemd service file
template:
src: ../templates/pod.service.j2
dest: /etc/systemd/system/quay-pod.service

- name: Check if pod pause image is loaded
command: podman inspect --type=image {{ pause_image }}
register: r
ignore_errors: yes

- name: Pull Infra image
containers.podman.podman_image:
name: "{{ pause_image }}"
when: r.rc != 0
retries: 5
delay: 5

- name: Start Quay Pod service
systemd:
name: quay-pod.service
enabled: yes
daemon_reload: yes
state: restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- name: Copy Postgres systemd service file
template:
src: ../templates/postgres.service.j2
dest: /etc/systemd/system/quay-postgres.service

- name: Check if Postgres image is loaded
command: podman inspect --type=image {{ postgres_image }}
register: pg
ignore_errors: yes

- name: Pull Postgres image
containers.podman.podman_image:
name: "{{ postgres_image }}"
when: pg.rc != 0
retries: 5
delay: 5

- name: Start Postgres service
systemd:
name: quay-postgres.service
enabled: yes
daemon_reload: yes
state: restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- name: Copy Quay systemd service file
template:
src: ../templates/quay.service.j2
dest: /etc/systemd/system/quay-app.service

- name: Check if Quay image is loaded
command: podman inspect --type=image {{ quay_image }}
register: q
ignore_errors: yes

- name: Pull Quay image
containers.podman.podman_image:
name: "{{ quay_image }}"
when: q.rc != 0
retries: 5
delay: 5

- name: Start Quay service
systemd:
name: quay-app.service
enabled: yes
daemon_reload: yes
state: restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- name: Copy Redis systemd service file
template:
src: ../templates/redis.service.j2
dest: /etc/systemd/system/quay-redis.service

- name: Check if Redis image is loaded
command: podman inspect --type=image {{ redis_image }}
register: r
ignore_errors: yes

- name: Pull Redis image
containers.podman.podman_image:
name: "{{ redis_image }}"
when: r.rc != 0
retries: 5
delay: 5

- name: Start Redis service
systemd:
name: quay-redis.service
enabled: yes
daemon_reload: yes
state: restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- name: Autodetect Image Archive
include_tasks: autodetect-image-archive.yaml

- name: Upgrade Quay Pod Service
include_tasks: upgrade-pod-service.yaml

- name: Upgrade Postgres Service
include_tasks: upgrade-postgres-service.yaml

- name: Upgrade Redis Service
include_tasks: upgrade-redis-service.yaml

- name: Upgrade Quay Service
include_tasks: upgrade-quay-service.yaml

- name: Wait for Quay
include_tasks: wait-for-quay.yaml
11 changes: 11 additions & 0 deletions ansible-runner/context/app/project/upgrade_mirror_appliance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: "Upgrade Mirror Appliance"
gather_facts: yes
become: true
hosts: all
tags:
- quay
tasks:
- name: upgrade_mirror_appliance
import_role:
name: mirror_appliance
tasks_from: upgrade
8 changes: 4 additions & 4 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func init() {
// Add install command
rootCmd.AddCommand(installCmd)

installCmd.Flags().StringVarP(&targetHostname, "targetHostname", "H", os.Getenv("HOST"), "The hostname of the target you wish to install Quay to. This defaults to $HOST")
installCmd.Flags().StringVarP(&targetHostname, "targetHostname", "H", getFQDN(), "The hostname of the target you wish to install Quay to. This defaults to $HOST")
installCmd.Flags().StringVarP(&targetUsername, "targetUsername", "u", os.Getenv("USER"), "The user on the target host which will be used for SSH. This defaults to $USER")
installCmd.Flags().StringVarP(&sshKey, "ssh-key", "k", os.Getenv("HOME")+"/.ssh/quay_installer", "The path of your ssh identity key. This defaults to ~/.ssh/quay_installer")

Expand Down Expand Up @@ -268,8 +268,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 redis_image=%s postgres_image=%s quay_hostname=%s local_install=%s quay_root=%s" install_mirror_appliance.yml %s %s`,
sshKey, targetUsername, targetHostname, initUser, initPassword, quayImage, redisImage, postgresImage, quayHostname, strconv.FormatBool(isLocalInstall()), quayRoot, askBecomePassFlag, additionalArgs)
`ansible-playbook -i %s@%s, --private-key /runner/env/ssh_key -e "init_user=%s init_password=%s quay_image=%s redis_image=%s postgres_image=%s pause_image=%s quay_hostname=%s local_install=%s quay_root=%s" install_mirror_appliance.yml %s %s`,
sshKey, targetUsername, targetHostname, initUser, initPassword, quayImage, redisImage, postgresImage, pauseImage, quayHostname, strconv.FormatBool(isLocalInstall()), quayRoot, askBecomePassFlag, additionalArgs)

log.Debug("Running command: " + podmanCmd)
cmd := exec.Command("bash", "-c", podmanCmd)
Expand All @@ -279,6 +279,6 @@ func install() {
err = cmd.Run()
check(err)

log.Printf("Quay installed successfully, permanent data are stored in %s", quayRoot)
log.Printf("Quay installed successfully, permanent data is stored in %s", quayRoot)
log.Printf("Quay is available at %s with credentials (%s, %s)", "https://"+quayHostname, initUser, initPassword)
}
Loading

0 comments on commit b7f8aca

Please sign in to comment.