Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch] Convert upgrade & uninstall functions to Python #1038

Merged
merged 32 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b9a3ca4
[patch] Convert upgrade function to Python
durera Jun 12, 2024
99e69b6
Updates
durera Jun 12, 2024
649ab5c
Updates
durera Jun 12, 2024
3083c4b
Updates
durera Jun 12, 2024
81251ec
Updates
durera Jun 12, 2024
72eafa5
Update permissions-updates.sh
durera Jun 12, 2024
a8ad8fc
Updates
durera Jun 12, 2024
0271340
Fixes
durera Jun 12, 2024
c0327be
Fix version sub
durera Jun 12, 2024
303a434
Updates
durera Jun 12, 2024
27cd714
Update build-cli.yml
durera Jun 12, 2024
2bad472
Update build-cli.yml
durera Jun 12, 2024
b466f05
Update build-cli.yml
durera Jun 12, 2024
208441f
Update build-cli.yml
durera Jun 12, 2024
3c62705
Update build-cli.yml
durera Jun 12, 2024
08a6cb1
Update build-cli.yml
durera Jun 12, 2024
1fd0ff7
Update build-cli.yml
durera Jun 12, 2024
29b5a5a
Update build-cli.yml
durera Jun 12, 2024
9aa8bfc
Update build-cli.yml
durera Jun 12, 2024
3f269ee
Update cli.py
durera Jun 12, 2024
16dea7c
Updates
durera Jun 12, 2024
e9f7582
Merge branch 'master' into python
durera Jun 13, 2024
5e371f8
Convert uninstall function to python
durera Jun 17, 2024
0811e99
Merge branch 'master' into python
durera Jun 17, 2024
9ec0c34
Updates
durera Jun 17, 2024
4cbc155
Split mas-devops and mas-cli projects
durera Jun 18, 2024
9c417bd
Need to mkdir templates (GH doesn't commit empty dirs)
durera Jun 18, 2024
be6b382
Merge branch 'master' into python
durera Jun 18, 2024
0aaa829
Fix actions logic
durera Jun 18, 2024
bb444ae
Fix paths
durera Jun 18, 2024
4d6fdd1
Update install-python-packages.sh
durera Jun 18, 2024
dd49964
Update MANIFEST.in
durera Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions .github/workflows/build-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ jobs:
build-cli:
runs-on: ubuntu-latest
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
# Without this option, we don't get the tag information
with:
fetch-depth: 0
Expand All @@ -23,21 +25,21 @@ jobs:
$GITHUB_WORKSPACE/build/bin/initbuild.sh
source $GITHUB_WORKSPACE/build/bin/.functions.sh

# 1. Download Ansible collection from Artifactory
# 2. Download Ansible collection from Artifactory
# -------------------------------------------------------------------------------------------
- name: Download Ansible collection from Artifactory
env:
ARTIFACTORY_GENERIC_RELEASE_URL: ${{ secrets.ARTIFACTORY_GENERIC_RELEASE_URL }}
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
run: |
if [[ -e $GITHUB_WORKSPACE/image/cli/install-ansible/ibm-mas_devops.tar.gz ]]; then
echo "Found a local Ansible collection to be used in $GITHUB_WORKSPACE/image/cli/install-ansible/ibm-mas_devops.tar.gz! Skip download from Artifactory..."
if [[ -e $GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz ]]; then
echo "Found a local Ansible collection to be used in $GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz! Skip download from Artifactory..."
else
echo "Downloading from ***/ibm-mas/ansible-devops/latest/ibm-mas_devops-latest.tar.gz"
wget --header="Authorization:Bearer $ARTIFACTORY_TOKEN" $ARTIFACTORY_GENERIC_RELEASE_URL/ibm-mas/ansible-devops/latest/ibm-mas_devops-latest.tar.gz -O $GITHUB_WORKSPACE/image/cli/install-ansible/ibm-mas_devops.tar.gz
wget --header="Authorization:Bearer $ARTIFACTORY_TOKEN" $ARTIFACTORY_GENERIC_RELEASE_URL/ibm-mas/ansible-devops/latest/ibm-mas_devops-latest.tar.gz -O $GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz
fi

# 2. Tekton
# 3. Tekton
# -------------------------------------------------------------------------------------------
- name: Build the Tekton definitions
run: $GITHUB_WORKSPACE/build/bin/build-tekton.sh
Expand All @@ -57,7 +59,23 @@ jobs:
$GITHUB_WORKSPACE/build/bin/artifactory-release.sh $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton.yaml
$GITHUB_WORKSPACE/build/bin/artifactory-release.sh $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton-fvt.yaml

# 3. CLI installer
# 4. Python Package
# -------------------------------------------------------------------------------------------
- name: Build the Python package
run: |
sed -i "s#__version__ = \"100.0.0\"#__version__ = \"${{ env.VERSION_NOPREREL }}\"#g" ${GITHUB_WORKSPACE}/python/src/mas/cli/__init__.py
cat ${GITHUB_WORKSPACE}/python/src/mas/cli/__init__.py
mkdir -p $GITHUB_WORKSPACE/python/src/mas/cli/templates
cp $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton.yaml $GITHUB_WORKSPACE/python/src/mas/cli/templates/ibm-mas-tekton.yaml
cd $GITHUB_WORKSPACE/python
python -m pip install --upgrade pip
pip install .[dev]
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
python -m build
cp $GITHUB_WORKSPACE/python/dist/mas_cli-${{ env.VERSION_NOPREREL }}.tar.gz $GITHUB_WORKSPACE/image/cli/install/mas_cli.tar.gz

# 5. CLI installer
# -------------------------------------------------------------------------------------------
- name: Build the cli package
run: |
Expand All @@ -70,7 +88,7 @@ jobs:
path: ${{ github.workspace }}/ibm-mas-cli-${{ env.VERSION }}.tgz
retention-days: 30

# 4. CLI container image
# 6. CLI container image
# -------------------------------------------------------------------------------------------
- name: Build the docker image
run: |
Expand All @@ -91,7 +109,7 @@ jobs:
# username: ${{ secrets.QUAYIO_USERNAME }}
# password: ${{ secrets.QUAYIO_PASSWORD }}

# 5. OWASP Dependency Check
# 7. OWASP Dependency Check
# -------------------------------------------------------------------------------------------
- name: Perform dependency check
uses: dependency-check/Dependency-Check_Action@main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.1
uses: actions/checkout@v4

- name: Install and Build
run: |
Expand Down
49 changes: 38 additions & 11 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
name: Release CLI
on:
push:
branches-ignore:
- '**'
tags:
- '**'
release:
types: [ published ]

permissions:
contents: read

jobs:
build-cli:
runs-on: ubuntu-latest
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
# Without this option, we don't get the tag information
with:
fetch-depth: 0

- name: Initialise the build system
run: |
chmod u+x $GITHUB_WORKSPACE/build/bin/*.sh
$GITHUB_WORKSPACE/build/bin/initbuild.sh
source $GITHUB_WORKSPACE/build/bin/.functions.sh

# 1. Tekton
# 2. Tekton
# -------------------------------------------------------------------------------------------
- name: Build the Tekton definitions
run: $GITHUB_WORKSPACE/build/bin/build-tekton.sh
Expand All @@ -40,8 +46,30 @@ jobs:
$GITHUB_WORKSPACE/build/bin/artifactory-release.sh $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton.yaml
$GITHUB_WORKSPACE/build/bin/artifactory-release.sh $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton-fvt.yaml

# 3. Python Package
# -------------------------------------------------------------------------------------------
- name: Build the Python package
run: |
sed -i "s#__version__ = \"100.0.0\"#__version__ = \"${{ env.VERSION_NOPREREL }}\"#g" ${GITHUB_WORKSPACE}/python/src/mas/cli/__init__.py
cat ${GITHUB_WORKSPACE}/python/src/mas/cli/__init__.py
mkdir -p $GITHUB_WORKSPACE/python/src/mas/cli/templates
cp $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton.yaml $GITHUB_WORKSPACE/python/src/mas/cli/templates/ibm-mas-tekton.yaml
cd $GITHUB_WORKSPACE/python
python -m pip install --upgrade pip
pip install .[dev]
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
python -m build
cp $GITHUB_WORKSPACE/python/dist/mas_cli-${{ env.VERSION_NOPREREL }}.tar.gz $GITHUB_WORKSPACE/image/cli/install/mas_cli.tar.gz

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: python/dist

# 2. CLI installer
# 4. CLI installer
# -------------------------------------------------------------------------------------------
- name: Build the cli package
run: |
Expand All @@ -56,8 +84,7 @@ jobs:
tag: ${{ github.ref }}
overwrite: true


# 3. CLI container image
# 5. CLI container image
# -------------------------------------------------------------------------------------------
- name: Build the docker image
run: |
Expand All @@ -80,7 +107,7 @@ jobs:
# username: ${{ secrets.QUAYIO_USERNAME }}
# password: ${{ secrets.QUAYIO_PASSWORD }}

# 4. OWASP Dependency Check
# 6. OWASP Dependency Check
# -------------------------------------------------------------------------------------------
- name: Perform dependency check
uses: dependency-check/Dependency-Check_Action@main
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/verify-cli-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Fail if local Ansible collection is present in PR to master
run: |
if [[ -e $GITHUB_WORKSPACE/image/cli/install-ansible/ibm-mas_devops.tar.gz ]]; then
echo "Found a local Ansible collection($GITHUB_WORKSPACE/image/cli/install-ansible/ibm-mas_devops.tar.gz) in this PR, Local ansible collection is not allowed in master branch. Failing build."
if [[ -e $GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz ]]; then
echo "Found a local Ansible collection($GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz) in this PR, Local ansible collection is not allowed in master branch. Failing build."
exit 1
fi
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

*.DS_Store*
.vscode

*.pyc

image/cli/mascli/templates/ibm-mas-tekton.yaml
Expand All @@ -12,3 +10,15 @@ tmp/
tekton/test-*.yaml
tekton/target
tekton/tmp

kubectl.exe
mas.log

python/pandoc-*-amd64.deb
python/dist
python/venv
python/src/mas_cli.egg-info
python/README.rst
python/src/mas/cli/templates/ibm-mas-tekton.yaml
/python/build
python/mas-upgrade.spec
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ The MAS Ansible Devops collection contains the ansible roles that are used to au
When building a MAS CLI pre-release image version, the build system will embed the MAS Ansible Devops `tar.gz` following the rule:

- By default, MAS CLI will build its pre-release image using [the latest MAS Ansible Devops released version](https://github.com/ibm-mas/ansible-devops/releases).
- **To use a custom MAS Ansible Devops collection within MAS CLI:** If you are developing a custom MAS Ansible Devops collection and you want to build a MAS CLI image that will make use of this ansible collection, from the `cli` root folder, you can run `make ansible-build` to build and place your MAS Ansible Devops `tar.gz` into [`cli/image/cli/install-ansible`](image/cli/install-ansible/), that's the folder that CLI uses to install the MAS Ansible Devops collection that will be used within the MAS CLI container during the image build process.
- **To use a custom MAS Ansible Devops collection within MAS CLI:** If you are developing a custom MAS Ansible Devops collection and you want to build a MAS CLI image that will make use of this ansible collection, from the `cli` root folder, you can run `make ansible-build` to build and place your MAS Ansible Devops `tar.gz` into [`cli/image/cli/install`](image/cli/install/), that's the folder that CLI uses to install the MAS Ansible Devops collection that will be used within the MAS CLI container during the image build process.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
.DEFAULT_GOAL := all

ansible-build:
ansible-galaxy collection build --output-path image/cli/install-ansible ../ansible-devops/ibm/mas_devops --force
mv image/cli/install-ansible/ibm-mas_devops-100.0.0.tar.gz image/cli/install-ansible/ibm-mas_devops.tar.gz
ansible-galaxy collection build --output-path image/cli/install ../ansible-devops/ibm/mas_devops --force
mv image/cli/install/ibm-mas_devops-100.0.0.tar.gz image/cli/install/ibm-mas_devops.tar.gz
ansible-install:
ansible-galaxy collection install image/cli/install-ansible/ibm-mas_devops.tar.gz --force --no-deps
ansible-galaxy collection install image/cli/install/ibm-mas_devops.tar.gz --force --no-deps
ansible: ansible-build ansible-install

tekton:
Expand All @@ -23,7 +23,7 @@ run:
docker run -ti cli:local

clean:
rm image/cli/install-ansible/ibm-mas_devops.tar.gz
rm image/cli/install/ibm-mas_devops.tar.gz
rm image/cli/bin/templates/ibm-mas-tekton.yaml

create:
Expand Down
15 changes: 13 additions & 2 deletions build/bin/.env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ if [ -f "$VERSION_FILE" ]; then
export VERSION=$(cat ${VERSION_FILE})
fi

export VERSION_FILE_NOPREREL=${GITHUB_WORKSPACE}/.version-noprerel
if [ -f "$VERSION_FILE_NOPREREL" ]; then
export VERSION_NOPREREL=$(cat ${VERSION_FILE_NOPREREL})
fi

# During initbuild we record the release level (aka the version bump from the last release)
export SEMVER_RELEASE_LEVEL_FILE=${GITHUB_WORKSPACE}/.releaselevel
if [ -f "$SEMVER_RELEASE_LEVEL_FILE" ]; then
Expand All @@ -27,14 +32,18 @@ if [ -z $BUILD_SYSTEM_ENV_LOADED ]; then
export BUILD_SYSTEM_ENV_LOADED=1

if [ ! -z $GITHUB_ENV ]; then
echo "GITHUB_ENV is defined, exporting properties to $GITHUB_ENV"
# https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#environment-files
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "GITHUB_ENV is defined, exporting properties to $GITHUB_ENV"

echo "VERSION_FILE=$VERSION_FILE" >> $GITHUB_ENV
echo "VERSION_FILE_NOPREREL=$VERSION_FILE_NOPREREL" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION_NOPREREL=$VERSION_NOPREREL" >> $GITHUB_ENV
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV

echo "SEMVER_RELEASE_LEVEL_FILE=$SEMVER_RELEASE_LEVEL_FILE" >> $GITHUB_ENV
echo "SEMVER_RELEASE_LEVEL=$SEMVER_RELEASE_LEVEL" >> $GITHUB_ENV

echo "BUILD_SYSTEM_ENV_LOADED=1" >> $GITHUB_ENV
else
echo "GITHUB_ENV is not defined"
Expand All @@ -45,7 +54,9 @@ if [ -z $BUILD_SYSTEM_ENV_LOADED ]; then
echo_highlight "PATH ....................... $PATH"
echo_highlight ""
echo_highlight "VERSION_FILE ............... $VERSION_FILE"
echo_highlight "VERSION_FILE_NOPREREL ...... $VERSION_FILE_NOPREREL"
echo_highlight "VERSION .................... $VERSION"
echo_highlight "VERSION_NOPREREL ........... $VERSION_NOPREREL"
echo_highlight "DOCKER_TAG ................. $DOCKER_TAG"
echo_highlight ""
echo_highlight "SEMVER_RELEASE_LEVEL_FILE .. $SEMVER_RELEASE_LEVEL_FILE"
Expand Down
2 changes: 2 additions & 0 deletions build/bin/initbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pip install --quiet pyyaml yamllint
# 1. Set up semantic versioning
# -----------------------------------------------------------------------------
VERSION_FILE=$GITHUB_WORKSPACE/.version
VERSION_FILE_NOPREREL=$GITHUB_WORKSPACE/.version-noprerel

if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
echo "Note: non-branch build for a tag named '${GITHUB_REF_NAME}'"
Expand Down Expand Up @@ -91,6 +92,7 @@ fi

# 2. Tweak version string for pre-release builds
# -----------------------------------------------------------------------------
cp $VERSION_FILE $VERSION_FILE_NOPREREL
if [[ "${GITHUB_REF_TYPE}" == "branch" ]]; then
semver bump prerel pre.$GITHUB_REF_NAME $(cat $VERSION_FILE) > $VERSION_FILE
echo "Pre-release build: $(cat $VERSION_FILE)"
Expand Down
29 changes: 12 additions & 17 deletions image/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM quay.io/ibmmas/cli-base:latest
ARG VERSION_LABEL

# Auto-expire the image in quay.io after 3 weeks
LABEL quay.expires-after=3w

# 1. Copy basics
COPY app-root/src/ /opt/app-root/src/
COPY mascli/ /mascli/
Expand All @@ -15,21 +18,13 @@ ENV ANSIBLE_COLLECTIONS_PATH=/opt/app-root/lib64/python3.9/site-packages/ansible
VERSION=${VERSION_LABEL:-x.y.z} \
VIRTUAL_ENV_DISABLE_PROMPT=1

# 3. Install Ansible collections -- do this last for efficient dev builds
# 4. Set file permissions to be developer (hack) friendly
COPY install-ansible /tmp/install-ansible
# 3. Install Python packages
# 4. Install Ansible collections
# 5. Set file permissions to be developer (hack) friendly
COPY install /tmp/install
RUN umask 0002 && \
bash /tmp/install-ansible/install-ansible-collections.sh && \
rm -rf /tmp/install-ansible && \
chmod -R ug+rwx /opt/app-root/src/env.sh && \
chmod -R ug+rwx /opt/app-root/src/.ansible && \
chmod +x /opt/app-root/src/*.sh && \
chmod +x /opt/app-root/src/.bashrc && \
chmod -R ug+w /mascli && \
chmod +x /mascli/mas && \
chmod +x /mascli/must-gather/* && \
chmod +x /mascli/backup-restore/* && \
chmod -R ug+w /masfvt && \
chmod +x /usr/bin/gather && \
chmod -R g+w $ANSIBLE_COLLECTIONS_PATH/ibm/mas_devops && \
ln -s $ANSIBLE_COLLECTIONS_PATH/ibm/mas_devops /mascli/ansible-devops
ls /tmp/install && \
bash /tmp/install/install-python-packages.sh && \
bash /tmp/install/install-ansible-collections.sh && \
bash /tmp/install/permissions-updates.sh && \
rm -rf /tmp/install
8 changes: 0 additions & 8 deletions image/cli/install-ansible/install-ansible-collections.sh

This file was deleted.

8 changes: 8 additions & 0 deletions image/cli/install/install-ansible-collections.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

ansible-galaxy collection install -r /tmp/install/requirements.yml -p $ANSIBLE_COLLECTIONS_PATH

if [[ -e /tmp/install/ibm-mas_devops.tar.gz ]]
then ansible-galaxy collection install /tmp/install/ibm-mas_devops.tar.gz -p $ANSIBLE_COLLECTIONS_PATH
else ansible-galaxy collection install ibm.mas_devops
fi
4 changes: 4 additions & 0 deletions image/cli/install/install-python-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

python3 -m pip install pip --upgrade
python3 -m pip install /tmp/install/mas_cli.tar.gz
16 changes: 16 additions & 0 deletions image/cli/install/permissions-updates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -x
set -e

chmod -R ug+rwx /opt/app-root/src/env.sh
chmod -R ug+rwx /opt/app-root/src/.ansible
chmod +x /opt/app-root/src/*.sh
chmod +x /opt/app-root/src/.bashrc
chmod -R ug+w /mascli
chmod +x /mascli/mas
chmod +x /mascli/must-gather/*
chmod +x /mascli/backup-restore/*
chmod -R ug+w /masfvt
chmod +x /usr/bin/gather
chmod -R g+w $ANSIBLE_COLLECTIONS_PATH/ibm/mas_devops
ln -s $ANSIBLE_COLLECTIONS_PATH/ibm/mas_devops /mascli/ansible-devops
Loading
Loading