Skip to content

Commit

Permalink
Add devspaces image building
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Sep 27, 2024
1 parent 5a92cfc commit 8ebdbc2
Show file tree
Hide file tree
Showing 22 changed files with 512 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
KUBEDOCK
accesslog
addinivalue
addoption
Expand All @@ -14,13 +15,15 @@ confest
containerfile
devcontainer
devel
devfile
endgroup
gunicorn
libera
microdnf
mknod
modifyitems
netcommon
opencontainers
pkgmgr
pylibssh
seccomp
Expand Down
3 changes: 3 additions & 0 deletions .config/pydoclint-baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests/conftest.py
DOC503: Method `Infrastructure.__post_init__` exceptions in the "Raises" section in the docstring do not match those in the function body Raises values in the docstring: ['ValueError', 'ValueError', 'ValueError']. Raised exceptions in the body: ['ValueError'].
--------------------
72 changes: 72 additions & 0 deletions .github/actions/build-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
name: Build & Test
description: Build the final container image and run tests on it

inputs:
registry:
description: Target registry to push the final image.
default: "localhost:5000"
namespace:
description: Namespace of the container image.
default: ansible
final_image:
description: Name of the final image.
default: ansible-workspace-env-reference
publish:
description: Publish the image to ghcr.io
default: "false"

runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare
shell: bash
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# network=host driver-opt needed to push to local registry
driver-opts: network=host
buildkitd-flags: --debug

- name: Build final image
id: build-final
uses: docker/build-push-action@v5
with:
context: ${{ github.workspace }}/devspaces/context
provenance: false
file: ${{ github.workspace }}/devspaces/Containerfile
load: true
tags: |
${{ inputs.namespace }}/${{ inputs.final_image }}:test
# cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
# cache-to: type=gha,scope=build-${{ env.PLATFORM_PAIR }}

- name: Docker meta
id: meta
if: ${{ inputs.publish == 'true' }}
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ inputs.namespace }}/${{ inputs.final_image }}
flavor: |
latest=false
tags: |
type=raw,value=latest
type=ref,event=tag
- name: Push the built image to ghcr.io
id: push-final
if: ${{ inputs.publish == 'true' }}
uses: docker/build-push-action@v5
with:
context: ${{ github.workspace }}/devspaces/context
provenance: false
file: ${{ github.workspace }}/devspaces/Containerfile
tags: ${{ steps.meta.outputs.tags }}
push: true
1 change: 1 addition & 0 deletions .github/actions/build-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ runs:
with:
# network=host driver-opt needed to push to local registry
driver-opts: network=host
buildkitd-flags: --debug

- name: Install or upgrade tools needed for the build and test
shell: bash
Expand Down
27 changes: 24 additions & 3 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ jobs:
build-image:
runs-on: ${{ matrix.builder }}
name: ${{ matrix.name }}
# commented to speedup execution
# needs: tox
# uses same runner for image building, but devspace image builds faster
needs:
- devspaces
services:
registry:
image: registry:2
Expand Down Expand Up @@ -88,9 +89,29 @@ jobs:
with:
registry: ghcr.io

devspaces:
runs-on: devtools-multiarch-builder
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build the devspaces image
uses: ./.github/actions/build-release
with:
publish: "{{ github.event_name == 'release' && github.event.action == 'published' && 'true' || 'false' }}"

pypi:
name: Publish to PyPI registry
needs: build-image
needs:
- build-image
- tox
if: github.event_name == 'release' && github.event.action == 'published'
environment: release # approval
runs-on: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ cython_debug/
_readthedocs

# ansible-builder
context
collections
/context
/collections
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ repos:
- id: toml-sort-fix

- repo: https://github.com/tox-dev/tox-ini-fmt
rev: 1.3.1
rev: 1.4.1
hooks:
- id: tox-ini-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.6.8
hooks:
- id: ruff
args:
Expand All @@ -72,15 +72,15 @@ repos:
name: Spell check with cspell

- repo: https://github.com/jsh9/pydoclint
rev: "0.5.6"
rev: "0.5.8"
hooks:
- id: pydoclint
# This allows automatic reduction of the baseline file when needed.
entry: sh -ec "pydoclint . && pydoclint --generate-baseline=1 ."
pass_filenames: false

- repo: https://github.com/pycqa/pylint.git
rev: v3.2.7
rev: v3.3.1
hooks:
- id: pylint
args:
Expand Down
2 changes: 1 addition & 1 deletion bindep.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python3-devel
python3-devel [platform:redhat]
22 changes: 22 additions & 0 deletions devspaces/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Version created and populated by setuptools_scm
/src/ansible_creator/_version.py

dist/

build/

*.egg-info

*.ruff_cache/

*.mypy_cache/

*.pytest_cache/

*.tox/

__pycache__/
.cache
_readthedocs
.coverage
coverage.xml
18 changes: 18 additions & 0 deletions devspaces/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM quay.io/devfile/universal-developer-image:ubi8-latest

ARG PYV=3.11

LABEL org.opencontainers.image.source=https://github.com/ansible/ansible-workspace-env-reference-image
LABEL org.opencontainers.image.authors="Ansible DevTools"
LABEL org.opencontainers.image.vendor="Red Hat"
LABEL org.opencontainers.image.licenses="GPL-3.0"
LABEL org.opencontainers.image.description="An OpenShift Dev Spaces container image for Ansible."

USER 0

WORKDIR /context
# install ansible-dev-tools specific packages and dependencies while avoiding
# adding multiple layers to the image.
RUN --mount=type=bind,target=. --mount=type=cache,dst=/var/cache/dnf --mount=type=cache,dst=/root/.cache/pip ./setup.sh

USER 10001
Loading

0 comments on commit 8ebdbc2

Please sign in to comment.