Skip to content

Commit

Permalink
feat: publish docker in infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelfimov committed Sep 18, 2024
1 parent dc3cd5b commit fb3de4c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/reusable-docker-publish-infrastructure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Publish Docker Images

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get list of changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
json: 'true'

- name: Output changed files
run: |
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
- name: Build and push Docker images
if: contains(steps.changed-files.outputs.all_changed_files, 'Dockerfile')
env:
REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create a list of directories containing Dockerfiles
DOCKERFILE_DIRS=$(echo "${{ steps.changed-files.outputs.files }}" | grep 'Dockerfile' | xargs -I {} dirname {} | sort -u)
# Build and push Docker images for each directory containing Dockerfile
for DIR in $DOCKERFILE_DIRS; do
echo "Building Docker image in directory $DIR"
IMAGE_NAME="${REPOSITORY_OWNER}/$(basename $DIR):latest"
docker build -t $IMAGE_NAME $DIR
echo $GITHUB_TOKEN | docker login ghcr.io -u $REPOSITORY_OWNER --password-stdin
docker push $IMAGE_NAME
done

0 comments on commit fb3de4c

Please sign in to comment.