diff --git a/.github/workflows/build-and-push-oci-cli-image.yml b/.github/workflows/build-and-push-oci-cli-image.yml index dce1eaebd0..d60c2e53f1 100644 --- a/.github/workflows/build-and-push-oci-cli-image.yml +++ b/.github/workflows/build-and-push-oci-cli-image.yml @@ -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" ] @@ -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 @@ -43,7 +64,7 @@ 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 @@ -51,6 +72,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Generate container image metadata + if: env.SKIP_BUILD != 'true' id: meta uses: docker/metadata-action@v5 with: @@ -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: @@ -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." \ No newline at end of file diff --git a/OracleCloudInfrastructure/oci-cli/Dockerfile b/OracleCloudInfrastructure/oci-cli/Dockerfile index cb2c94a0eb..30e70b0a5c 100644 --- a/OracleCloudInfrastructure/oci-cli/Dockerfile +++ b/OracleCloudInfrastructure/oci-cli/Dockerfile @@ -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 \