kciter / aws-ecr-action

This Action allows you to create Docker images and push into a ECR repository.
MIT License
146 stars 116 forks source link

How to pass timestamp for tags #6

Closed vinodjayachandran closed 4 years ago

vinodjayachandran commented 4 years ago

For Tags is it possible to pass a Unix expression to take the current time stamp. Example below

tags:date +%F-%I-%M``

ghost commented 4 years ago

Similar question from me... I can't seem to pass a variable in to the tags field, e.g. ${GITHUB_REF##*/} should work but doesn't. I want tags to be dynamic from the repo,

vinodjayachandran commented 4 years ago

I figured out a way to do it. Refer here - https://github.com/vinodjayachandran/spring-boot-docker/blob/master/.github/workflows/aws_ecr.yml

dasheck0 commented 4 years ago

I had the same issue. I wanted to add two tags. One with the branch as a denotation for the latest develop, master etc. And a concatenation of branch and package.json version, as it is a nodejs project. Here is my resulting (and working) yml file

name: Build and deploy docker image to ECR

on:
  push:
    branches: [master, develop]

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: get-npm-version
        uses: martinbeentjes/npm-get-version-action@master
        id: package-version

      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: branch

      - name: Build and push image
        uses: kciter/aws-ecr-action@v1
        with:
          access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          account_id: ${{ secrets.AWS_ACCOUNT_ID }}
          repo: ...
          region: eu-central-1
          tags: ${{ steps.branch.outputs.branch }}-${{ steps.package-version.outputs.current-version }},${{ steps.branch.outputs.branch }}

Hope this helps. Also the order of the tags was somewhat relevant. When I changed it I got a weird error where the action tried to take the tag as host for the docker url. Might be a bug. Take this and a clean NodeJS project as MWE for reproduction.