-
Notifications
You must be signed in to change notification settings - Fork 0
40 lines (33 loc) · 1.19 KB
/
docker-build.yaml
File metadata and controls
40 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: Build and Push Docker Images
on:
push:
branches:
- main
pull_request:
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Log in to GitHub Docker Registry
- name: Log in to GitHub Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Loop through each folder in /services and build/push Docker images
- name: Build and push Docker images
run: |
for service in services/*; do
if [ -d "$service" ] && [ -f "$service/Dockerfile" ]; then
# Extract the service name from the folder name
service_name=$(basename "$service")
# Build the Docker image
docker build -t ghcr.io/${{ github.repository_owner }}/${{ github.repository }}-$service_name:latest $service
# Push the Docker image to GitHub Packages
docker push ghcr.io/${{ github.repository_owner }}/${{ github.repository }}-$service_name:latest
fi
done