Skip to content

Commit

Permalink
Add container registry and image name as variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Fethbita committed Oct 6, 2024
1 parent b71cb6f commit 3658c25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
18 changes: 5 additions & 13 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ name: Build and Push Docker Image

on:
push:
branches: [ "main" ]
paths: ['Dockerfile']
pull_request:
branches: [ "main" ]
paths: ['Dockerfile']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
CARGO_TERM_COLOR: always
CONTAINER_REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_IMAGE_NAME }}

jobs:
build-and-push-image:
Expand All @@ -20,15 +17,10 @@ jobs:
packages: write

steps:
- name: Set image name to lowercase
id: img-name
run: |
echo "image_name=${REGISTRY}/${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]' >>${GITHUB_OUTPUT}
- name: Login to container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ env.REGISTRY }}
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -37,11 +29,11 @@ jobs:
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
push: true
tags: ${{ steps.img-name.outputs.image_name }}:latest,${{ steps.img-name.outputs.image_name }}:${{ github.sha }}
tags: ${{ env.CONTAINER_REGISTRY }}/${{ env.CONTAINER_IMAGE_NAME }}:latest,${{ env.CONTAINER_REGISTRY }}/${{ env.CONTAINER_IMAGE_NAME }}:${{ github.sha }}

- if: github.ref_name != github.event.repository.default_branch
name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
push: true
tags: ${{ steps.img-name.outputs.image_name }}:${{ github.sha }}
tags: ${{ env.CONTAINER_REGISTRY }}/${{ env.CONTAINER_IMAGE_NAME }}:${{ github.sha }}
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ on:

env:
CARGO_TERM_COLOR: always
CONTAINER_REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_IMAGE_NAME }}

jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}:latest
image: ${{ env.CONTAINER_REGISTRY }}/${{ env.CONTAINER_IMAGE_NAME }}:latest

steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 #v4.2.0
Expand Down

0 comments on commit 3658c25

Please sign in to comment.