# Sorting gitlab container registry by date

**URL:** https://renku.discourse.group/t/sorting-gitlab-container-registry-by-date/1083
**Category:** General
**Created:** [18 September 2024 07:16 UTC](https://renku.discourse.group/t/sorting-gitlab-container-registry-by-date/1083 "2024-09-18T07:16:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![firat](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@firat](https://renku.discourse.group/u/firat)
#### Post date: [18 September 2024 07:16 UTC](https://renku.discourse.group/t/sorting-gitlab-container-registry-by-date/1083/1 "2024-09-18T07:16:46Z")

</div>

I need to get renkulab container for renku v2 from the container registry of a repo, but I can only sort the list on Name (see Fig below).  
I don’t know if I can have any power over the tag of the image that will be built automatically by renku runners, but so far I only have commit hashes, which are not the easiest to sort through.  
Can we add an option to sort the built containers by date built/published?

 ![image](https://global.discourse-cdn.com/free1/uploads/renku/original/1X/cf82b661e7ff638a79d6eebbab7b1ea1ae4e2153.png)

---

<div class="post-metadata">

### Author: ![leafty](https://yyz2.discourse-cdn.com/free1/user_avatar/renku.discourse.group/leafty/32/796_2.png) [@leafty](https://renku.discourse.group/u/leafty)
#### Post date: [18 September 2024 07:24 UTC](https://renku.discourse.group/t/sorting-gitlab-container-registry-by-date/1083/2 "2024-09-18T07:24:32Z")

</div>

In your `.gitlab-ci.yml` file, you can update the docker image tag to also include the branch name.

Before:

```yaml
  script: |
    CI_COMMIT_SHA_7=$(echo $CI_COMMIT_SHA | cut -c1-7)
    docker build --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA_7 .
    docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA_7

```

After:

```yaml
  script: |
    CI_COMMIT_SHA_7=$(echo $CI_COMMIT_SHA | cut -c1-7)
    docker build --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA_7 --tag CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME .
    docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA_7
    docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME

```

This way you can use the string `oadat-read:main` or `oadat-read:master` (depending on your repository). Note that the image used for sessions will then depend on what is currently tagged image.

---

<div class="post-metadata">

### Author: ![leafty](https://yyz2.discourse-cdn.com/free1/user_avatar/renku.discourse.group/leafty/32/796_2.png) [@leafty](https://renku.discourse.group/u/leafty)
#### Post date: [18 September 2024 07:28 UTC](https://renku.discourse.group/t/sorting-gitlab-container-registry-by-date/1083/3 "2024-09-18T07:28:00Z")

</div>

> [@firat](#):
>
> Can we add an option to sort the built containers by date built/published?

I don’t think we have the resources to change the interface and APIs of the docker registry and/or GitLab, unfortunately.

---

<div class="post-metadata">

### Author: ![firat](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@firat](https://renku.discourse.group/u/firat)
#### Post date: [18 September 2024 07:37 UTC](https://renku.discourse.group/t/sorting-gitlab-container-registry-by-date/1083/4 "2024-09-18T07:37:59Z")

</div>

Thanks! Adding branch name is already a good step forward. I wonder if we can tag it with current date somehow, because that would be a suitable work around for me.

---

<div class="post-metadata">

### Author: ![leafty](https://yyz2.discourse-cdn.com/free1/user_avatar/renku.discourse.group/leafty/32/796_2.png) [@leafty](https://renku.discourse.group/u/leafty)
#### Post date: [18 September 2024 07:46 UTC](https://renku.discourse.group/t/sorting-gitlab-container-registry-by-date/1083/5 "2024-09-18T07:46:08Z")

</div>

```yaml
script: |
    CI_COMMIT_SHA_7=$(echo $CI_COMMIT_SHA | cut -c1-7)
    TODAY=$(echo $CI_JOB_STARTED_AT | cut -c1-10)
    docker build --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA_7 --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME --tag $CI_REGISTRY_IMAGE:$TODAY .
    docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA_7
    docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
    docker push $CI_REGISTRY_IMAGE:$TODAY

```

Note that maybe this should be adapted so that the date tag is only pushed from the default branch.
