mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-23 00:05:09 +00:00
ci: refactor Docker build to trigger on release only
- Replaces workflow_run trigger with release.published - Builds Docker image only when semantic-release publishes a new tag - Tags image with immutable version and either :latest or :dev based on stability - Removes unnecessary artifact dependencies and fallback tag logic
This commit is contained in:
parent
46748bbb5b
commit
2d3d24ef0e
1 changed files with 19 additions and 46 deletions
65
.github/workflows/docker-build.yml
vendored
65
.github/workflows/docker-build.yml
vendored
|
|
@ -1,79 +1,52 @@
|
||||||
name: Digikwal stable
|
name: Digikwal stable
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_run:
|
release:
|
||||||
workflows:
|
types: [published]
|
||||||
- Semantic Release
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Download release metadata
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: release-metadata
|
|
||||||
path: ./artifacts/release-metadata
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
repository: digikwal/frappe_docker
|
|
||||||
run-id: ${{ github.event.workflow_run.id }}
|
|
||||||
|
|
||||||
- name: Load release metadata
|
|
||||||
run: |
|
|
||||||
export RELEASE_TAG=$(cat ./artifacts/release-metadata/release_tag.txt)
|
|
||||||
export FRAPPE_BRANCH=$(cat ./artifacts/release-metadata/frappe_branch.txt)
|
|
||||||
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
|
|
||||||
echo "FRAPPE_BRANCH=$FRAPPE_BRANCH" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USER }}
|
username: ${{ secrets.DOCKER_USER }}
|
||||||
password: ${{ secrets.DOCKER_PAT }}
|
password: ${{ secrets.DOCKER_PAT }}
|
||||||
|
|
||||||
- name: Encode apps.json
|
- name: Setup enviroment variables
|
||||||
run: |
|
run: |
|
||||||
export APPS_JSON_BASE64=$(base64 -w 0 ./apps.json)
|
export APPS_JSON_BASE64=$(base64 < ./apps.json | tr -d '\n')
|
||||||
echo "APPS_JSON_BASE64=$APPS_JSON_BASE64" >> $GITHUB_ENV
|
echo "APPS_JSON_BASE64=$APPS_JSON_BASE64" >> $GITHUB_ENV
|
||||||
|
echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Build Docker image
|
- name: Build Docker image
|
||||||
run: |
|
run: |
|
||||||
docker build \
|
docker build \
|
||||||
--build-arg FRAPPE_PATH=https://github.com/frappe/frappe \
|
--build-arg FRAPPE_PATH=https://github.com/frappe/frappe \
|
||||||
--build-arg FRAPPE_BRANCH=${{ env.FRAPPE_BRANCH }} \
|
--build-arg FRAPPE_BRANCH=version-15 \
|
||||||
--build-arg APPS_JSON_BASE64=${{ env.APPS_JSON_BASE64 }} \
|
--build-arg APPS_JSON_BASE64=${{ env.APPS_JSON_BASE64 }} \
|
||||||
--tag digikwal/erpnext:${{ env.RELEASE_TAG }} \
|
--tag digikwal/erpnext:${{ env.TAG_NAME }} \
|
||||||
--file images/layered/Containerfile .
|
--file images/layered/Containerfile .
|
||||||
|
|
||||||
- name: Push Docker image and tags
|
- name: Push Docker image and tags
|
||||||
env:
|
env:
|
||||||
DOCKER_IMAGE: digikwal/erpnext
|
DOCKER_IMAGE: digikwal/erpnext
|
||||||
run: |
|
run: |
|
||||||
TAG="${RELEASE_TAG}"
|
echo "Using immutable tag: $TAG_NAME"
|
||||||
IMAGE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
||||||
https://hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags/${TAG}/)
|
docker push ${DOCKER_IMAGE}:${TAG_NAME}
|
||||||
|
|
||||||
if [ "$IMAGE_EXISTS" = "200" ]; then
|
if [[ "$TAG_NAME" == *"-"* ]]; then
|
||||||
echo "Image with tag $TAG already exists. Adding unique suffix..."
|
echo "Detected prerelease. Tagging as dev..."
|
||||||
SUFFIX=$(git rev-parse --short HEAD)
|
docker tag ${DOCKER_IMAGE}:${TAG_NAME} ${DOCKER_IMAGE}:dev
|
||||||
TAG="${TAG}-${SUFFIX}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Using tag: $TAG"
|
|
||||||
docker tag ${DOCKER_IMAGE}:${RELEASE_TAG} ${DOCKER_IMAGE}:${TAG}
|
|
||||||
docker push ${DOCKER_IMAGE}:${TAG}
|
|
||||||
|
|
||||||
if [[ "$TAG" != *"-"* ]]; then
|
|
||||||
docker tag ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGE}:latest
|
|
||||||
docker push ${DOCKER_IMAGE}:latest
|
|
||||||
else
|
|
||||||
docker tag ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGE}:dev
|
|
||||||
docker push ${DOCKER_IMAGE}:dev
|
docker push ${DOCKER_IMAGE}:dev
|
||||||
|
else
|
||||||
|
echo "Detected stable release. Tagging as latest..."
|
||||||
|
docker tag ${DOCKER_IMAGE}:${TAG_NAME} ${DOCKER_IMAGE}:latest
|
||||||
|
docker push ${DOCKER_IMAGE}:latest
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue