-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (97 loc) · 3.4 KB
/
Copy pathpublish_docker.yml
File metadata and controls
110 lines (97 loc) · 3.4 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Publish Docker Image to GHCR
on:
push:
branches:
- main
tags:
- 'v*.*.*' # Semantic versioning pattern
pull_request:
# This triggers on any PR, but we filter by source branch in the job
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Only continue for PRs if the source branch is dev or release
- name: Check PR source branch
if: github.event_name == 'pull_request'
run: |
echo "PR source branch: ${{ github.head_ref }}"
if [[ "${{ github.head_ref }}" != "dev" && "${{ github.head_ref }}" != "release" ]]; then
echo "Not a PR from dev or release branch. Skipping workflow."
exit 1
fi
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
run: |
IMAGE_NAME=ghcr.io/eed-solutions/eed_docker_python_uv
TAG=latest
SHOULD_BUILD_PUSH=false
echo "GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME"
echo "GITHUB_REF: $GITHUB_REF"
echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF"
# Determine context: PR or push/tag
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
BRANCH_NAME="$GITHUB_HEAD_REF"
REF_TYPE="pr"
elif [[ "$GITHUB_REF" == refs/heads/* ]]; then
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
REF_TYPE="branch"
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
BRANCH_NAME="${GITHUB_REF#refs/tags/}"
REF_TYPE="tag"
else
BRANCH_NAME=""
REF_TYPE=""
fi
echo "REF_TYPE: $REF_TYPE"
echo "BRANCH_NAME: $BRANCH_NAME"
# Determine tag and build indicator based on context
if [[ "$REF_TYPE" == "branch" || "$REF_TYPE" == "pr" ]]; then
case "$BRANCH_NAME" in
"main")
TAG=main
SHOULD_BUILD_PUSH=true
;;
"dev")
TAG=dev
SHOULD_BUILD_PUSH=true
;;
"release")
TAG=release
SHOULD_BUILD_PUSH=true
;;
*)
TAG="$BRANCH_NAME"
;;
esac
elif [[ "$REF_TYPE" == "tag" ]]; then
TAG="$BRANCH_NAME"
if [[ "$BRANCH_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
SHOULD_BUILD_PUSH=true
fi
fi
echo "Determined TAG: $TAG"
echo "SHOULD_BUILD_PUSH: $SHOULD_BUILD_PUSH"
# Build and push the image if indicated
if [[ "$SHOULD_BUILD_PUSH" == "true" ]]; then
docker build -t $IMAGE_NAME:$TAG -f .devcontainer/Dockerfile .
docker push $IMAGE_NAME:$TAG
else
echo "Skipping build and push: not a main/dev/release branch or semantic version tag."
fi
# Push additional 'latest' tag for semantic version tags
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
docker tag $IMAGE_NAME:$TAG $IMAGE_NAME:latest
docker push $IMAGE_NAME:latest
fi