Skip to content

Commit

Permalink
Add required permission to the action (#105)
Browse files Browse the repository at this point in the history
* Add required permission to the action

* Add ability to provide version from action input

* Change input type

* Change condition type

* Change condition type
  • Loading branch information
s-vitaliy authored Jul 2, 2024
1 parent a551d61 commit 8624956
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions .github/workflows/publish-ecr-public.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
name: Publish Arcane to ECR public registry
run-name: Deploy ${{github.ref_name}} to public.ecr.aws by @${{ github.actor }}

on: workflow_dispatch
on:
workflow_dispatch:
inputs:
version:
description: |
Version number to publish. Defaults to the latest git tag in the repository.
This version MUST exist in the ghcr.io registry.
required: false
default: "current"

env:
PROJECT_NAME: Arcane.Operator
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
create_release:
name: Create Release
publish_image:
name: Publish Docker Image to ECR Public
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags') }}

permissions:
contents: read
id-token: write

steps:

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0


- name: Get project version
uses: SneaksAndData/github-actions/[email protected]
id: current_version

- name: Set up variables
env:
VERSION: ${{ inputs.version }}
CURRENT_VERSION: ${{steps.current_version.outputs.version}}
run: |
test "$VERSION" == "current" && echo "IMAGE_VERSION=$CURRENT_VERSION" >> ${GITHUB_ENV} || echo "IMAGE_VERSION=$VERSION" >> ${GITHUB_ENV}
- name: Import AWS Secrets
uses: hashicorp/[email protected]
with:
Expand All @@ -39,26 +69,22 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Amazon ECR Public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Get project version
uses: SneaksAndData/github-actions/[email protected]
id: version

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=${{steps.version.outputs.version}}
type=semver,pattern={{version}},value=${{ env.IMAGE_VERSION }}
flavor:
latest=false

- name: Push image to ECR Public registry
uses: akhilerm/[email protected]
with:
Expand Down

0 comments on commit 8624956

Please sign in to comment.