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

add cli version tag to build pipeline #2938

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 34 additions & 5 deletions .github/workflows/build-and-push-oci-cli-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name: Build and Push OCI CLI Image
on:
workflow_dispatch:
schedule:
- cron: '30 0 * * 3' # Tuesday@17h30 Pacific = Wednesday@00h30 UTC
- cron: '0 * * * *' # Runs every hour
push:
branches: [ "main" ]
paths:
- 'OracleCloudInfrastructuree/oci-cli/*'
- 'OracleCloudInfrastructure/oci-cli/*'
- '.github/workflows/build-and-push-oci-cli-image.yml'
pull_request:
paths:
- 'OracleCloudInfrastructuree/oci-cli/*'
- 'OracleCloudInfrastructure/oci-cli/*'
- '.github/workflows/build-and-push-oci-cli-image.yml'
branches: [ "main" ]

Expand All @@ -31,10 +31,31 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Fetch latest OCI CLI version
id: fetch-version
run: |
OCI_CLI_VERSION=$(curl -s https://pypi.org/pypi/oci-cli/json | jq -r .info.version)
echo "Latest OCI CLI version: $OCI_CLI_VERSION"
echo "VERSION=$OCI_CLI_VERSION" >> "$GITHUB_ENV"

- name: Check if image with this version already exists
id: check-image
run: |
IMAGE_TAG="ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$VERSION"
echo "Checking if image $IMAGE_TAG exists..."
if docker manifest inspect $IMAGE_TAG > /dev/null 2>&1; then
echo "Image already exists, skipping build."
echo "SKIP_BUILD=true" >> "$GITHUB_ENV"
else
echo "Image does not exist, proceeding with build."
fi

- name: Set up QEMU
if: env.SKIP_BUILD != 'true'
uses: docker/setup-qemu-action@v3

- name: Setup Docker BuildX
- name: Set up Docker BuildX
if: env.SKIP_BUILD != 'true'
uses: docker/setup-buildx-action@v3

- name: Lowercase repository owner
Expand All @@ -43,14 +64,15 @@ jobs:
echo "repo-owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"

- name: Log into GitHub Container Registry
if: github.event_name != 'pull_request'
if: env.SKIP_BUILD != 'true' && github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate container image metadata
if: env.SKIP_BUILD != 'true'
id: meta
uses: docker/metadata-action@v5
with:
Expand All @@ -63,16 +85,19 @@ jobs:
org.opencontainers.image.licenses=UPL-1.0
org.opencontainers.image.vendor=${REPO_OWNER}
org.opencontainers.image.title=OCI CLI
org.opencontainers.image.version=${{ env.VERSION }}
org.opencontainers.image.description=Oracle Cloud Infrastructure Command Line Interface
org.opencontainers.image.source=https://github.com/oracle/docker-images/tree/main/OracleCloudInfrastructure/oci-cli
org.opencontainers.image.documentation=https://docs.oracle.com/en-us/iaas/Content/API/Concepts/cliconcepts.htm
org.opencontainers.image.url=https://github.com/${{ steps.repo-owner.outputs.repo-owner }}/docker-images/pkgs/container/oci-cli
org.opencontainers.image.base.name=ghcr.io/${{ steps.repo-owner.outputs.repo-owner }}/oci-cli:latest
tags: |
type=raw,value=${{ env.VERSION }}
type=schedule,pattern={{date 'YYYYMMDD'}}
type=sha

- name: Build and push image
if: env.SKIP_BUILD != 'true'
id: build-and-push
uses: docker/build-push-action@v6
with:
Expand All @@ -85,3 +110,7 @@ jobs:
platforms: linux/amd64, linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Skip build notification
if: env.SKIP_BUILD == 'true'
run: echo "Skipping build since the image for OCI CLI version $VERSION already exists."
2 changes: 1 addition & 1 deletion OracleCloudInfrastructure/oci-cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENV IMAGE_BUILDTIME=${BUILDTIME} \

RUN dnf -y install jq && rm -rf /var/cache/dnf/* \
&& python3 -m pip install --no-cache-dir --upgrade pip \
&& python3 -m pip install --no-cache-dir oci-cli \
&& python3 -m pip install --no-cache-dir oci-cli==${VERSION} \
&& cp /usr/local/lib/python3.9/site-packages/oci_cli/bin/oci_autocomplete.sh /usr/local/bin/oci_autocomplete.sh \
&& chmod +x /usr/local/bin/oci_autocomplete.sh \
&& useradd -m -d /oracle oracle \
Expand Down