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
59
.github/workflows/docker-build.yml
vendored
59
.github/workflows/docker-build.yml
vendored
|
|
@ -1,79 +1,52 @@
|
|||
name: Digikwal stable
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows:
|
||||
- Semantic Release
|
||||
types:
|
||||
- completed
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
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
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USER }}
|
||||
password: ${{ secrets.DOCKER_PAT }}
|
||||
|
||||
- name: Encode apps.json
|
||||
- name: Setup enviroment variables
|
||||
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 "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build \
|
||||
--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 }} \
|
||||
--tag digikwal/erpnext:${{ env.RELEASE_TAG }} \
|
||||
--tag digikwal/erpnext:${{ env.TAG_NAME }} \
|
||||
--file images/layered/Containerfile .
|
||||
|
||||
- name: Push Docker image and tags
|
||||
env:
|
||||
DOCKER_IMAGE: digikwal/erpnext
|
||||
run: |
|
||||
TAG="${RELEASE_TAG}"
|
||||
IMAGE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||
https://hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags/${TAG}/)
|
||||
echo "Using immutable tag: $TAG_NAME"
|
||||
|
||||
if [ "$IMAGE_EXISTS" = "200" ]; then
|
||||
echo "Image with tag $TAG already exists. Adding unique suffix..."
|
||||
SUFFIX=$(git rev-parse --short HEAD)
|
||||
TAG="${TAG}-${SUFFIX}"
|
||||
fi
|
||||
docker push ${DOCKER_IMAGE}:${TAG_NAME}
|
||||
|
||||
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
|
||||
if [[ "$TAG_NAME" == *"-"* ]]; then
|
||||
echo "Detected prerelease. Tagging as dev..."
|
||||
docker tag ${DOCKER_IMAGE}:${TAG_NAME} ${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
|
||||
|
|
|
|||
Loading…
Reference in a new issue