# Image tagging rollbacks

While preparing your docker builds and releases its a good idea to tag your images. Digger uses a default tag of :latest but this means that to rollback to a previous version of your code you would need to rebuild that tag or branch.

With the digger cli you can specify tags in the cli. you need to do that for your build-push-release cycles.

dg env build --tag v1
dg env push --tag v1
dg env release --tag v1

This way you can trigger a release for a previous version by passing the v1 tag. You can also use the same tags for a CI/CD setting. For example, in a GitHub Action, you can trigger the action everytime a version tag is pushed:

name: Digger CI
      - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10

    runs-on: ubuntu-16.04
      tag_version: ${{ steps.get_tag.outputs.VERSION }}
      stage: ${{ steps.get_stage.outputs.STAGE }}
      - name: Set the tag version
        id: get_tag
        run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3)

    runs-on: ubuntu-16.04
      - get_tag_version
      - name: Checkout
        uses: actions/checkout@v1

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: eu-west-1

      - name: Set up Python 3.8
        uses: actions/setup-python@v2
          python-version: "3.8"

      - name: Build and push and release
          DIGGER_TOKEN: ${{ secrets.DIGGER_TOKEN }}
          DIGGER_AWS_KEY: ${{ secrets.DIGGER_AWS_KEY }}
          DIGGER_AWS_SECRET: ${{ secrets.DIGGER_AWS_SECRET }}
          BACKEND_ENDPOINT: "https://backend.digger.dev"
          WEBAPP_ENDPOINT: "https://app.digger.dev"
        run: |
          export TAG_VERSION=${{needs.get_tag_version.outputs.tag_version}}

          # Install diggercli
          pip install --upgrade git+https://github.com/diggerhq/cli@master

          echo "> Building docker image"
          dg env build stage --service svc1 --tag $TAG_VERSION
          echo "> Pushing docker image to ECR"
          dg env push stage --service svc1 --tag $TAG_VERSION --aws-key "$DIGGER_AWS_KEY" --aws-secret "$DIGGER_AWS_SECRET"
          echo "> Releasing"
          dg env push release --service svc1 --tag $TAG_VERSION --aws-key "$DIGGER_AWS_KEY" --aws-secret "$DIGGER_AWS_SECRET"

In the above snippet we listen for changes to changes in a tag push and use the same tag to build and push with dg. This means that to rollback a previous version one can re-run a previous workflow.