Docker tagging strategy in CI

In our CI system we have a step to build a Docker image. Actually we have 2 jobs.

The first job will build a base image that includes all the external dependencies. This job will only run if the Dockerfile has changed.

Then we have some test jobs that use the most recent version of the base image.

If that also passes we have a second job that is using the most recent base image to create an image that already includes our source code as well and the compiled versions of the code that need compilation. Till now we taged everything with “latest”, but it is not a good solution. I wonder if there are recommended ways to tag the images. Especially given that we also start to use branches and Merge-Requests so we have to decide how to tag the images that might have been created in a branch and what to use during the merge request?