Skip to content

Commit 72bd1d2

Browse files
authored
feat: add capi driver to magnum (#906)
Signed-off-by: Kevin Carter <[email protected]>
1 parent ae9e649 commit 72bd1d2

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#
2+
name: Create and Publish a Magnum Image
3+
4+
on:
5+
push:
6+
paths:
7+
- .github/workflows/release-magnum-rxt.yml
8+
- Containerfiles/MagnumRXT-Containerfile
9+
branches:
10+
- development
11+
- main
12+
workflow_dispatch:
13+
inputs:
14+
imageTag:
15+
description: Set tag for the image
16+
required: true
17+
default: 2024.1-ubuntu_jammy
18+
type: choice
19+
options:
20+
- master
21+
- 2024.1-ubuntu_jammy
22+
pluginTag:
23+
description: 'Set release used for the build environment'
24+
required: true
25+
default: master
26+
type: choice
27+
options:
28+
- master
29+
30+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
31+
env:
32+
REGISTRY: ghcr.io
33+
IMAGE_NAME: ${{ github.repository }}
34+
DEF_TAG_NAME: 2024.1-ubuntu_jammy
35+
36+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
37+
jobs:
38+
build-and-push-image:
39+
outputs:
40+
MY_DATE: ${{ steps.mydate.outputs.MY_DATE }}
41+
MY_CONTAINER: ${{ steps.mycontainer.outputs.MY_CONTAINER }}
42+
runs-on: ubuntu-latest
43+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
44+
permissions:
45+
contents: read
46+
packages: write
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
51+
- name: Log in to the Container registry
52+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
53+
with:
54+
registry: ${{ env.REGISTRY }}
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
# ghcr only allows lowercase repository names
58+
- name: lowercase repo name
59+
run: |
60+
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
61+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
62+
- name: Extract metadata (tags, labels) for Docker
63+
id: meta
64+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
65+
with:
66+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
67+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
68+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
69+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
70+
- name: Dynamically set MY_DATE environment variable
71+
run: echo "MY_DATE=$(date +%s)" >> $GITHUB_ENV
72+
- name: Build and push Docker image
73+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
74+
with:
75+
context: .
76+
file: Containerfiles/MagnumRXT-Containerfile
77+
push: true
78+
tags: |
79+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/magnum:${{ github.event.inputs.imageTag || env.DEF_TAG_NAME }}
80+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/magnum:${{ github.event.inputs.imageTag || env.DEF_TAG_NAME }}-${{ env.MY_DATE }}
81+
labels: ${{ steps.meta.outputs.labels }}
82+
build-args: |
83+
VERSION=${{ github.event.inputs.imageTag || env.DEF_TAG_NAME }}
84+
PLUGIN_VERSION=${{ github.event.inputs.pluginTag }}
85+
- name: Dynamically set MY_CONTAINER output option
86+
id: mycontainer
87+
run: echo "MY_CONTAINER=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/magnum:${{ github.event.inputs.imageTag }}-${{ env.MY_DATE }}" >> $GITHUB_OUTPUT
88+
- name: Dynamically set MY_DATE output option
89+
id: mydate
90+
run: echo "MY_DATE=${{ env.MY_DATE }}" >> $GITHUB_OUTPUT
91+
92+
change-original-images:
93+
runs-on: ubuntu-latest
94+
needs: [build-and-push-image]
95+
permissions:
96+
contents: write
97+
pull-requests: write
98+
steps:
99+
- name: Checkout repository
100+
uses: actions/checkout@v4
101+
- name: Dynamically update the original images file
102+
run: jq '. + ["${{ needs.build-and-push-image.outputs.MY_CONTAINER }}"] | sort' .original-images.json | tee .original-images.json.new
103+
- name: Rewrite original images file
104+
run: mv .original-images.json.new .original-images.json
105+
- name: Create Pull Request
106+
id: cpr
107+
uses: peter-evans/create-pull-request@v7
108+
with:
109+
commit-message: Update original images with new container
110+
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
111+
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
112+
signoff: false
113+
branch: ${{ needs.build-and-push-image.outputs.MY_DATE }}
114+
sign-commits: true
115+
delete-branch: true
116+
title: 'chore: Update original images'
117+
body: |
118+
Update container image
119+
- Updated original image file with container ${{needs.build-and-push-image.outputs.MY_CONTAINER}}
120+
change request Auto-generated
121+
labels: |
122+
container images
123+
automated pr
124+
draft: false
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG VERSION=master-ubuntu_jammy
2+
FROM openstackhelm/magnum:${VERSION} as build
3+
ARG PLUGIN_VERSION=master
4+
RUN apt-get update && apt-get install -y git && apt clean
5+
RUN export ORIG_PLUGIN_VERSION="${PLUGIN_VERSION}"; \
6+
if [ "${PLUGIN_VERSION}" != 'master' ]; then export PLUGIN_VERSION=stable/${PLUGIN_VERSION}; fi; \
7+
/var/lib/openstack/bin/activate; \
8+
/var/lib/openstack/bin/pip install git+https://github.com/openstack/oslo.db@${PLUGIN_VERSION}#egg=oslo_db \
9+
git+https://opendev.org/openstack/magnum-capi-helm@${PLUGIN_VERSION}#egg=magnum_capi_helm
10+
RUN /var/lib/openstack/bin/pip install --upgrade --force-reinstall pip
11+
RUN find /var/lib/openstack -regex '^.*\(__pycache__\|\.py[co]\)$' -delete
12+
13+
FROM openstackhelm/magnum:${VERSION}
14+
COPY --from=build /var/lib/openstack/. /var/lib/openstack/

0 commit comments

Comments
 (0)