Closed vinodjayachandran closed 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,
I figured out a way to do it. Refer here - https://github.com/vinodjayachandran/spring-boot-docker/blob/master/.github/workflows/aws_ecr.yml
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.
For Tags is it possible to pass a Unix expression to take the current time stamp. Example below
tags:
date +%F-%I-%M``