Skip to content

Commit a2f6bc3

Browse files
committed
reset action
1 parent 4842812 commit a2f6bc3

1 file changed

Lines changed: 45 additions & 41 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
1-
name: Build and Push Docker Image
1+
name: Build and Publish Docker Image on Tag
22

33
on:
44
push:
5-
branches:
6-
- '**' # all branches
75
tags:
8-
- 'v*' # tags
6+
- 'v*' # Trigger the workflow when a new tag starting with 'v' is pushed
97

108
jobs:
11-
docker:
9+
build:
1210
runs-on: ubuntu-latest
1311

12+
permissions:
13+
actions: read
14+
contents: read
15+
packages: write
16+
1417
steps:
15-
- name: Checkout source
16-
uses: actions/checkout@v4
17-
18-
- name: Set up Docker Buildx
19-
uses: docker/setup-buildx-action@v3
20-
21-
- name: Log in to Docker Hub
22-
uses: docker/login-action@v3
23-
with:
24-
username: ${{ secrets.DOCKER_USERNAME }}
25-
password: ${{ secrets.DOCKER_PASSWORD }}
26-
27-
- name: Extract Git ref and tag
28-
id: extract
29-
run: |
30-
echo "GIT_REF=${GITHUB_REF}" >> $GITHUB_OUTPUT
31-
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
32-
33-
# Extract sanitized branch name or tag
34-
if [[ "${GITHUB_REF}" == refs/heads/* ]]; then
35-
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
36-
TAG_NAME=$(echo "${BRANCH_NAME}" | tr '[:upper:]' '[:lower:]' | sed 's#[^a-z0-9_.-]#-#g')
37-
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
38-
TAG_NAME="${GITHUB_REF#refs/tags/}"
39-
else
40-
TAG_NAME="unknown"
41-
fi
42-
43-
echo "DOCKER_TAG=${TAG_NAME}" >> $GITHUB_OUTPUT
44-
45-
- name: Build and push Docker image
46-
uses: docker/build-push-action@v5
47-
with:
48-
context: .
49-
push: true
50-
tags: ghcr.io/ximeraproject/server:${{ steps.extract.outputs.DOCKER_TAG }}
18+
# Step 1: Set up Docker Buildx (supports layer caching)
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
22+
# Step 2: Restore cache for Docker layers
23+
- name: Cache Docker layers
24+
uses: actions/cache@v4
25+
with:
26+
path: /tmp/.buildx-cache
27+
key: buildx-cache-${{ github.sha }}
28+
restore-keys: |
29+
buildx-cache-${{ github.sha }}
30+
buildx-cache-
31+
buildx
32+
33+
# Step 3: Check out the repository
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
37+
# # Step 4: Log in to registry
38+
- name: Log into registry
39+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
40+
41+
- name: Initialize cache directory
42+
run: mkdir -p /tmp/.buildx-cache
43+
44+
- name: Debug cache
45+
run: ls -l /tmp/.buildx-cache
46+
47+
# Step 5: Build and push the Docker image with caching
48+
- name: Build and Push Docker image
49+
run: |
50+
docker buildx build \
51+
--cache-from=type=local,src=/tmp/.buildx-cache \
52+
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
53+
--tag ghcr.io/ximeraproject/ximeraserver:${{ github.ref_name }} \
54+
--push .

0 commit comments

Comments
 (0)