diff options
author | Shane McDonald <me@shanemcd.com> | 2021-10-13 16:28:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 16:28:23 +0200 |
commit | 4ab2539c8ac68a215336f36e5e55519343bc4ea8 (patch) | |
tree | 4bc125bef51f53a953c01b22b82f36e8c06d23dc | |
parent | Merge pull request #11208 from AlexSCorey/7741-GroupAdvanceSearchKeys (diff) | |
parent | Add awx-operator CI check (diff) | |
download | awx-4ab2539c8ac68a215336f36e5e55519343bc4ea8.tar.xz awx-4ab2539c8ac68a215336f36e5e55519343bc4ea8.zip |
Merge pull request #11242 from shanemcd/awx-operator-ci-check
Add awx-operator CI check
-rw-r--r-- | .dockerignore | 1 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 38 | ||||
-rw-r--r-- | .yamllint | 3 | ||||
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | docs/build_awx_image.md | 7 | ||||
-rw-r--r-- | tools/ansible/build.yml | 25 | ||||
-rw-r--r-- | tools/ansible/roles/dockerfile/defaults/main.yml | 1 | ||||
-rwxr-xr-x | tools/ansible/roles/dockerfile/files/launch_awx.sh | 2 | ||||
-rw-r--r-- | tools/ansible/roles/dockerfile/templates/Dockerfile.j2 | 21 | ||||
-rw-r--r-- | tools/ansible/roles/image_build/defaults/main.yml | 5 | ||||
-rw-r--r-- | tools/ansible/roles/image_build/tasks/main.yml | 25 | ||||
-rw-r--r-- | tools/ansible/roles/image_push/defaults/main.yml | 4 | ||||
-rw-r--r-- | tools/ansible/roles/image_push/tasks/main.yml | 43 |
13 files changed, 137 insertions, 53 deletions
diff --git a/.dockerignore b/.dockerignore index c35f8a393f..57b3e57461 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ awx/ui/node_modules Dockerfile +.git diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce0673c2b6..ca9de5ee7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -175,3 +175,41 @@ jobs: run: | docker run -u $(id -u) --rm -v ${{ github.workspace}}:/awx_devel/:Z \ --workdir=/awx_devel ghcr.io/${{ github.repository_owner }}/awx_devel:${{ env.BRANCH }} make ui-test + awx-operator: + runs-on: ubuntu-latest + steps: + - name: Checkout awx + uses: actions/checkout@v2 + with: + path: awx + + - name: Checkout awx-operator + uses: actions/checkout@v2 + with: + repository: ansible/awx-operator + path: awx-operator + + - name: Install playbook dependencies + run: | + python3 -m pip install docker + + - name: Build AWX image + working-directory: awx + run: | + ansible-playbook -v tools/ansible/build.yml \ + -e headless=yes \ + -e awx_image=awx \ + -e awx_image_tag=ci \ + -e ansible_python_interpreter=$(which python3) + + - name: Run test deployment with awx-operator + working-directory: awx-operator + run: | + python3 -m pip install -r molecule/requirements.txt + ansible-galaxy collection install -r molecule/requirements.yml + sudo rm -f $(which kustomize) + make kustomize + KUSTOMIZE_PATH=$(readlink -f bin/kustomize) molecule test -s kind + env: + AWX_TEST_IMAGE: awx + AWX_TEST_VERSION: ci @@ -6,8 +6,11 @@ ignore: | # vault files awx/main/tests/data/ansible_utils/playbooks/valid/vault.yml awx/ui/test/e2e/tests/smoke-vars.yml + awx/ui/node_modules + tools/docker-compose/_sources extends: default rules: line-length: disable + truthy: disable @@ -379,7 +379,7 @@ clean-ui: awx/ui/node_modules: NODE_OPTIONS=--max-old-space-size=4096 $(NPM_BIN) --prefix awx/ui --loglevel warn ci -$(UI_BUILD_FLAG_FILE): +$(UI_BUILD_FLAG_FILE): awx/ui/node_modules $(PYTHON) tools/scripts/compilemessages.py $(NPM_BIN) --prefix awx/ui --loglevel warn run compile-strings $(NPM_BIN) --prefix awx/ui --loglevel warn run build @@ -391,7 +391,9 @@ $(UI_BUILD_FLAG_FILE): cp -r awx/ui/build/static/media/* awx/public/static/media touch $@ -ui-release: awx/ui/node_modules $(UI_BUILD_FLAG_FILE) + + +ui-release: $(UI_BUILD_FLAG_FILE) ui-devel: awx/ui/node_modules @$(MAKE) -B $(UI_BUILD_FLAG_FILE) @@ -420,10 +422,17 @@ dev_build: release_build: $(PYTHON) setup.py release_build -dist/$(SDIST_TAR_FILE): ui-release VERSION +HEADLESS ?= no +ifeq ($(HEADLESS), yes) +dist/$(SDIST_TAR_FILE): +else +dist/$(SDIST_TAR_FILE): $(UI_BUILD_FLAG_FILE) +endif $(PYTHON) setup.py $(SDIST_COMMAND) + ln -sf $(SDIST_TAR_FILE) dist/awx.tar.gz sdist: dist/$(SDIST_TAR_FILE) + echo $(HEADLESS) @echo "#############################################" @echo "Artifacts:" @echo dist/$(SDIST_TAR_FILE) diff --git a/docs/build_awx_image.md b/docs/build_awx_image.md index 8ca0a36d63..4530e06458 100644 --- a/docs/build_awx_image.md +++ b/docs/build_awx_image.md @@ -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: diff --git a/tools/ansible/build.yml b/tools/ansible/build.yml index a8bd2552f9..51b2b81c3b 100644 --- a/tools/ansible/build.yml +++ b/tools/ansible/build.yml @@ -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 diff --git a/tools/ansible/roles/dockerfile/defaults/main.yml b/tools/ansible/roles/dockerfile/defaults/main.yml index 6c568356f0..c4760f7b97 100644 --- a/tools/ansible/roles/dockerfile/defaults/main.yml +++ b/tools/ansible/roles/dockerfile/defaults/main.yml @@ -1,6 +1,7 @@ --- build_dev: false kube_dev: false +headless: no dockerfile_dest: '../..' dockerfile_name: 'Dockerfile' template_dest: '_build' diff --git a/tools/ansible/roles/dockerfile/files/launch_awx.sh b/tools/ansible/roles/dockerfile/files/launch_awx.sh index ac5a204d65..8a7af3c4de 100755 --- a/tools/ansible/roles/dockerfile/files/launch_awx.sh +++ b/tools/ansible/roles/dockerfile/files/launch_awx.sh @@ -17,6 +17,4 @@ set -e wait-for-migrations -awx-manage collectstatic --noinput --clear - supervisord -c /etc/supervisord.conf diff --git a/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 b/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 index 9289617c7b..4f8d40fa2d 100644 --- a/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 +++ b/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 @@ -11,6 +11,7 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 + USER root # Install build dependencies @@ -27,7 +28,9 @@ RUN dnf -y update && \ libffi-devel \ libtool-ltdl-devel \ make \ +{% if not headless|bool %} nodejs \ +{% endif %} nss \ openldap-devel \ patch \ @@ -44,6 +47,7 @@ RUN dnf -y update && \ RUN python3.8 -m ensurepip && pip3 install "virtualenv < 20" + # Install & build requirements ADD Makefile /tmp/Makefile RUN mkdir /tmp/requirements @@ -54,18 +58,29 @@ ADD requirements/requirements.txt \ RUN cd /tmp && make requirements_awx +ARG VERSION +ARG SETUPTOOLS_SCM_PRETEND_VERSION +ARG HEADLESS + {% if (build_dev|bool) or (kube_dev|bool) %} ADD requirements/requirements_dev.txt /tmp/requirements RUN cd /tmp && make requirements_awx_dev {% else %} # Use the distro provided npm to bootstrap our required version of node -RUN npm install -g n && n 14.15.1 && dnf remove -y nodejs + +{% if not headless|bool %} +RUN npm install -g n && n 14.15.1 +{% endif %} # Copy source into builder, build sdist, install it into awx venv COPY . /tmp/src/ WORKDIR /tmp/src/ -RUN make sdist && \ - /var/lib/awx/venv/awx/bin/pip install dist/awx-$(cat VERSION).tar.gz +RUN make sdist && /var/lib/awx/venv/awx/bin/pip install dist/awx.tar.gz + +{% if not headless|bool %} +RUN /var/lib/awx/venv/awx/bin/awx-manage collectstatic --noinput --clear +{% endif %} + {% endif %} # Final container(s) diff --git a/tools/ansible/roles/image_build/defaults/main.yml b/tools/ansible/roles/image_build/defaults/main.yml index a3e367c175..328f78cc1d 100644 --- a/tools/ansible/roles/image_build/defaults/main.yml +++ b/tools/ansible/roles/image_build/defaults/main.yml @@ -1,2 +1,5 @@ --- -awx_image: quay.io/ansible/awx +awx_image: ansible/awx +awx_image_tag: "{{ awx_version }}" +dockerfile_name: 'Dockerfile' +headless: no diff --git a/tools/ansible/roles/image_build/tasks/main.yml b/tools/ansible/roles/image_build/tasks/main.yml index 22120b4b75..9a1fb10c1b 100644 --- a/tools/ansible/roles/image_build/tasks/main.yml +++ b/tools/ansible/roles/image_build/tasks/main.yml @@ -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 }}/../../" diff --git a/tools/ansible/roles/image_push/defaults/main.yml b/tools/ansible/roles/image_push/defaults/main.yml new file mode 100644 index 0000000000..58bea4bcf8 --- /dev/null +++ b/tools/ansible/roles/image_push/defaults/main.yml @@ -0,0 +1,4 @@ +--- +registry: quay.io +awx_image: ansible/awx +awx_image_tag: "{{ awx_version }}" diff --git a/tools/ansible/roles/image_push/tasks/main.yml b/tools/ansible/roles/image_push/tasks/main.yml index 9561af8ac8..40ca906feb 100644 --- a/tools/ansible/roles/image_push/tasks/main.yml +++ b/tools/ansible/roles/image_push/tasks/main.yml @@ -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 }}" |