mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
Refactor image_build and image_push roles
Primary changes are: - Generalized variable names (remove "docker") - Add explicit "push" variable rather than checking if the "registry" variable is defined. - Allow for passing in version as build arg
This commit is contained in:
parent
84ffa4a5b7
commit
c9b53cf975
@ -1,2 +1,3 @@
|
||||
awx/ui/node_modules
|
||||
Dockerfile
|
||||
.git
|
||||
|
||||
@ -5,7 +5,10 @@
|
||||
To build a custom awx image to use with the awx-operator, use the `build_image` role:
|
||||
|
||||
```
|
||||
$ ansible-playbook tools/ansible/build.yml -v -e awx_image=registry.example.com/awx -e awx_version=test
|
||||
$ ansible-playbook tools/ansible/build.yml \
|
||||
-e registry=registry.example.com \
|
||||
-e awx_image=ansible/awx \
|
||||
-e awx_version=test -v
|
||||
```
|
||||
|
||||
> Note: The development image (`make docker-compose-build`) will not work with the awx-operator, the UI is not built in that image, among other things (see Dockerfile.j2 for more info).
|
||||
@ -21,7 +24,7 @@ $ docker push registry.example.com/awx:test
|
||||
## Using this image with the awx-operator
|
||||
|
||||
In the spec section of the `my-awx.yml` file described in the [install docs](./../INSTALL.md#deploy-awx),
|
||||
specify the new custom image.
|
||||
specify the new custom image.
|
||||
|
||||
```
|
||||
spec:
|
||||
|
||||
@ -2,7 +2,24 @@
|
||||
- name: Build AWX Docker Images
|
||||
hosts: localhost
|
||||
gather_facts: true
|
||||
roles:
|
||||
- {role: dockerfile}
|
||||
- {role: image_build}
|
||||
- {role: image_push, when: "docker_registry is defined"}
|
||||
tasks:
|
||||
- name: Get version from SCM if not explicitly provided
|
||||
shell: |
|
||||
python setup.py --version | cut -d + -f -1
|
||||
args:
|
||||
chdir: '../../'
|
||||
register: setup_py_version
|
||||
when: awx_version is not defined
|
||||
|
||||
- name: Set awx_version
|
||||
set_fact:
|
||||
awx_version: "{{ setup_py_version.stdout }}"
|
||||
when: awx_version is not defined
|
||||
|
||||
- include_role:
|
||||
name: dockerfile
|
||||
- include_role:
|
||||
name: image_build
|
||||
- include_role:
|
||||
name: image_push
|
||||
when: push | default(false) | bool
|
||||
|
||||
@ -54,6 +54,9 @@ ADD requirements/requirements.txt \
|
||||
|
||||
RUN cd /tmp && make requirements_awx
|
||||
|
||||
ARG VERSION
|
||||
ARG SETUPTOOLS_SCM_PRETEND_VERSION
|
||||
|
||||
{% if (build_dev|bool) or (kube_dev|bool) %}
|
||||
ADD requirements/requirements_dev.txt /tmp/requirements
|
||||
RUN cd /tmp && make requirements_awx_dev
|
||||
|
||||
@ -1,2 +1,5 @@
|
||||
---
|
||||
awx_image: quay.io/ansible/awx
|
||||
awx_image: ansible/awx
|
||||
awx_image_tag: "{{ awx_version }}"
|
||||
dockerfile_name: 'Dockerfile'
|
||||
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
---
|
||||
- name: Set global version if not provided
|
||||
set_fact:
|
||||
awx_version: "{{ lookup('file', playbook_dir + '/../../VERSION') }}"
|
||||
when: awx_version is not defined
|
||||
|
||||
- name: Verify awx-logos directory exists for official install
|
||||
stat:
|
||||
path: "../../../awx-logos"
|
||||
@ -17,11 +12,19 @@
|
||||
dest: "../../awx/ui/public/static/media/"
|
||||
when: awx_official|default(false)|bool
|
||||
|
||||
- set_fact:
|
||||
command_to_run: |
|
||||
docker build -t {{ awx_image }}:{{ awx_image_tag }} \
|
||||
-f {{ dockerfile_name }} \
|
||||
--build-arg VERSION={{ awx_version }} \
|
||||
--build-arg SETUPTOOLS_SCM_PRETEND_VERSION={{ awx_version }} \
|
||||
--build-arg HEADLESS={{ headless }} \
|
||||
.
|
||||
|
||||
# Calling Docker directly because docker-py doesnt support BuildKit
|
||||
- name: Build AWX image
|
||||
command: docker build -t {{ awx_image }}:{{ awx_version }} -f ../../{{ dockerfile_name }} ../..
|
||||
|
||||
- name: Tag awx images as latest
|
||||
command: "docker tag {{ item }}:{{ awx_version }} {{ item }}:latest"
|
||||
with_items:
|
||||
- "{{ awx_image }}"
|
||||
shell: "{{ command_to_run }}"
|
||||
environment:
|
||||
DOCKER_BUILDKIT: 1
|
||||
args:
|
||||
chdir: "{{ playbook_dir }}/../../"
|
||||
|
||||
4
tools/ansible/roles/image_push/defaults/main.yml
Normal file
4
tools/ansible/roles/image_push/defaults/main.yml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
registry: quay.io
|
||||
awx_image: ansible/awx
|
||||
awx_image_tag: "{{ awx_version }}"
|
||||
@ -1,33 +1,22 @@
|
||||
---
|
||||
- name: Authenticate with Docker registry if registry password given
|
||||
docker_login:
|
||||
registry: "{{ docker_registry }}"
|
||||
username: "{{ docker_registry_username }}"
|
||||
password: "{{ docker_registry_password }}"
|
||||
registry: "{{ registry }}"
|
||||
username: "{{ registry_username }}"
|
||||
password: "{{ registry_password }}"
|
||||
reauthorize: true
|
||||
when: docker_registry is defined and docker_registry_password is defined
|
||||
|
||||
- name: Remove local images to ensure proper push behavior
|
||||
block:
|
||||
- name: Remove awx image
|
||||
docker_image:
|
||||
name: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_image }}"
|
||||
tag: "{{ awx_version }}"
|
||||
state: absent
|
||||
when:
|
||||
- registry is defined
|
||||
- registry_username is defined
|
||||
- registry_password is defined
|
||||
|
||||
- name: Tag and Push Container Images
|
||||
block:
|
||||
- name: Tag and push awx image to registry
|
||||
docker_image:
|
||||
name: "{{ awx_image }}"
|
||||
repository: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_image }}"
|
||||
tag: "{{ item }}"
|
||||
push: true
|
||||
with_items:
|
||||
- "latest"
|
||||
- "{{ awx_version }}"
|
||||
|
||||
- name: Set full image path for Registry
|
||||
set_fact:
|
||||
awx_docker_actual_image: >-
|
||||
{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_image }}:{{ awx_version }}
|
||||
docker_image:
|
||||
name: "{{ awx_image }}:{{ awx_version }}"
|
||||
repository: "{{ registry }}/{{ awx_image }}:{{ item }}"
|
||||
force_tag: yes
|
||||
push: true
|
||||
source: local
|
||||
with_items:
|
||||
- "latest"
|
||||
- "{{ awx_version }}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user