Skip to content

Commit 33bafef

Browse files
lajosnagyquixLajos NagyPeter Nagy
authored
Fix push container (#9)
* testing actions workflow * testing push * test * fix attempt * test * push fix * repo clash * retrigger * push helm * test * test * more test * helm push attempt * test push * fix testing * test * combine steps * test * test * repo name fix * test * argh * trying module * trigger * test * version * old method * helm native * fix * fix * trying another model * again * github? * eh * why * more fallback * yes * hey * last ditch * fixing paths * update changes for helm->deploy * whitespaces * deploy check * yes * removed unused env var and comments * app version fix * more verbose logging for latest * correct version with chart --------- Co-authored-by: Lajos Nagy <[email protected]> Co-authored-by: Peter Nagy <[email protected]>
1 parent 8e1e238 commit 33bafef

File tree

4 files changed

+281
-67
lines changed

4 files changed

+281
-67
lines changed

.github/workflows/build.yml

Lines changed: 257 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ on:
1010
env:
1111
REGISTRY: docker.io
1212
IMAGE_NAME: quixanalytics/quix-environment-operator
13-
HELM_REGISTRY: oci://registry-1.docker.io/quixanalytics
13+
HELM_REPO_NAME: quixanalytics/quix-environment-operator-helm
1414

1515
jobs:
1616
extract-versions:
1717
runs-on: ubuntu-latest
1818
outputs:
19-
app_version: ${{ steps.original_versions.outputs.APP_VERSION }}
20-
chart_version: ${{ steps.original_versions.outputs.CHART_VERSION }}
19+
app_version: ${{ steps.versions.outputs.APP_VERSION }}
20+
chart_version: ${{ steps.versions.outputs.CHART_VERSION }}
21+
pr_number: ${{ steps.pr_info.outputs.PR_NUMBER }}
2122
steps:
2223
- name: Checkout repository
2324
uses: actions/checkout@v4
@@ -27,76 +28,96 @@ jobs:
2728
run: |
2829
APP_VERSION=$(grep 'appVersion:' deploy/quix-environment-operator/Chart.yaml | awk '{print $2}' | tr -d '"')
2930
CHART_VERSION=$(grep '^version:' deploy/quix-environment-operator/Chart.yaml | awk '{print $2}')
30-
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
31-
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV
32-
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_OUTPUT
33-
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_OUTPUT
31+
echo "Original appVersion: $APP_VERSION (for Docker) and chartVersion: $CHART_VERSION (for Helm)"
32+
echo "ORIG_APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
33+
echo "ORIG_CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV
34+
35+
- name: Get PR info
36+
id: pr_info
37+
run: |
38+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
39+
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
40+
else
41+
echo "PR_NUMBER=0" >> $GITHUB_OUTPUT
42+
fi
3443
35-
- name: Set development versions for non-main branch
36-
if: github.ref != 'refs/heads/main'
44+
- name: Set versions
45+
id: versions
3746
run: |
38-
DEV_VERSION="0.0.${{ github.run_number }}"
39-
echo "Using development version: $DEV_VERSION"
40-
echo "APP_VERSION=$DEV_VERSION" >> $GITHUB_ENV
41-
echo "CHART_VERSION=$DEV_VERSION" >> $GITHUB_ENV
47+
echo "Current GitHub ref: ${{ github.ref }}"
48+
echo "Is main branch? ${{ github.ref == 'refs/heads/main' }}"
4249
43-
# Update Chart.yaml with development versions
44-
sed -i "s/^version:.*/version: $DEV_VERSION/" deploy/quix-environment-operator/Chart.yaml
45-
sed -i "s/^appVersion:.*/appVersion: \"$DEV_VERSION\"/" deploy/quix-environment-operator/Chart.yaml
50+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
51+
# For main branch, use the original versions from Chart.yaml
52+
APP_VERSION="${ORIG_APP_VERSION}"
53+
CHART_VERSION="${ORIG_CHART_VERSION}"
54+
echo "Using original versions for main branch"
55+
else
56+
# For non-main branch, use development version
57+
DEV_VERSION="0.0.${{ github.run_number }}"
58+
APP_VERSION="${DEV_VERSION}"
59+
CHART_VERSION="${DEV_VERSION}"
60+
echo "Using development version for non-main branch: $DEV_VERSION"
61+
62+
# Update Chart.yaml with development versions
63+
sed -i "s/^version:.*/version: $DEV_VERSION/" deploy/quix-environment-operator/Chart.yaml
64+
sed -i "s/^appVersion:.*/appVersion: \"$DEV_VERSION\"/" deploy/quix-environment-operator/Chart.yaml
65+
66+
# Show modified Chart.yaml for verification
67+
echo "Modified Chart.yaml:"
68+
cat deploy/quix-environment-operator/Chart.yaml
69+
fi
4670
47-
# Show modified Chart.yaml for verification
48-
echo "Modified Chart.yaml:"
49-
cat deploy/quix-environment-operator/Chart.yaml
71+
# Update values.yaml with the correct image tag
72+
echo "Updating values.yaml with image tag: $APP_VERSION"
73+
sed -i "s/tag: \"latest\"/tag: \"$APP_VERSION\"/" deploy/quix-environment-operator/values.yaml
74+
echo "Modified values.yaml:"
75+
cat deploy/quix-environment-operator/values.yaml | grep -A 3 "image:"
76+
77+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
78+
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV
79+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_OUTPUT
80+
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_OUTPUT
81+
echo "Final versions - appVersion: $APP_VERSION, chartVersion: $CHART_VERSION"
5082
51-
build-docker:
83+
build-test-push-docker:
5284
needs: extract-versions
5385
runs-on: ubuntu-latest
5486
permissions:
5587
contents: read
88+
packages: write
5689
steps:
5790
- name: Checkout repository
5891
uses: actions/checkout@v4
5992

93+
- name: Debug branch info
94+
run: |
95+
echo "Current GitHub ref: ${{ github.ref }}"
96+
echo "Is main branch? ${{ github.ref == 'refs/heads/main' }}"
97+
echo "App version: ${{ needs.extract-versions.outputs.app_version }}"
98+
git branch --show-current
99+
git rev-parse --abbrev-ref HEAD
100+
60101
- name: Set up Docker Buildx
61102
uses: docker/setup-buildx-action@v3
62103

104+
- name: Display Docker image version
105+
run: |
106+
echo "Building Docker image with appVersion: ${{ needs.extract-versions.outputs.app_version }}"
107+
echo "Docker image will be tagged as: ${REGISTRY}/${IMAGE_NAME}:${{ needs.extract-versions.outputs.app_version }}"
108+
63109
- name: Build Docker image
64110
run: |
111+
# Use appVersion for Docker image
65112
export IMG="${REGISTRY}/${IMAGE_NAME}:${{ needs.extract-versions.outputs.app_version }}"
66113
make docker-build
67-
echo "Docker image built successfully"
68-
69-
build-helm:
70-
needs: extract-versions
71-
runs-on: ubuntu-latest
72-
permissions:
73-
contents: read
74-
steps:
75-
- name: Checkout repository
76-
uses: actions/checkout@v4
77-
78-
- name: Set up Helm
79-
uses: azure/setup-helm@v3
80-
with:
81-
version: 'latest'
82-
83-
- name: Package and lint Helm chart
114+
echo "Docker image built successfully with tag: $IMG"
115+
116+
- name: Run tests in Docker
84117
run: |
85-
make helm-lint
86-
make helm-package
87-
echo "Helm chart packaged successfully"
88-
89-
push-docker:
90-
needs: [extract-versions, build-docker]
91-
if: github.event_name != 'pull_request'
92-
runs-on: ubuntu-latest
93-
permissions:
94-
contents: read
95-
packages: write
96-
steps:
97-
- name: Checkout repository
98-
uses: actions/checkout@v4
99-
118+
make docker-test
119+
echo "All tests passed successfully"
120+
100121
- name: Log in to Docker Hub
101122
uses: docker/login-action@v3
102123
with:
@@ -105,34 +126,205 @@ jobs:
105126

106127
- name: Push Docker image
107128
run: |
129+
# Push with appVersion tag
108130
export IMG="${REGISTRY}/${IMAGE_NAME}:${{ needs.extract-versions.outputs.app_version }}"
109131
make docker-push
132+
echo "Pushed Docker image with appVersion tag: $IMG"
110133
111-
# Add and push latest tag for main branch
112-
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
113-
docker tag ${IMG} ${REGISTRY}/${IMAGE_NAME}:latest
114-
docker push ${REGISTRY}/${IMAGE_NAME}:latest
134+
# For main branch, also tag as latest
135+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
136+
echo "Pushing latest tag for Docker image"
137+
LATEST_IMG="${REGISTRY}/${IMAGE_NAME}:latest"
138+
docker tag ${IMG} ${LATEST_IMG}
139+
docker push ${LATEST_IMG}
140+
echo "Pushed Docker image with latest tag: ${LATEST_IMG}"
141+
else
142+
echo "Skipping latest tag for non-main branch: ${{ github.ref }}"
115143
fi
144+
116145
echo "Docker image pushed successfully"
117146
118-
push-helm:
119-
needs: [extract-versions, build-helm]
120-
if: github.event_name != 'pull_request'
147+
build-and-push-helm:
148+
needs: extract-versions
121149
runs-on: ubuntu-latest
122150
permissions:
123-
contents: read
124-
packages: write
151+
contents: write # Needed for creating releases
152+
pages: write # Needed for GitHub Pages
125153
steps:
126154
- name: Checkout repository
127155
uses: actions/checkout@v4
156+
with:
157+
fetch-depth: 0 # Required for chart-releaser to find chart changes
158+
159+
- name: Configure Git
160+
run: |
161+
git config user.name "${{ github.actor }}"
162+
git config user.email "${{ github.actor }}@users.noreply.github.com"
163+
164+
- name: Create gh-pages branch if needed
165+
run: |
166+
# Save current branch name
167+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
168+
echo "Current branch: ${CURRENT_BRANCH}"
169+
170+
# Check if gh-pages branch exists
171+
if ! git ls-remote --heads origin gh-pages | grep -q 'gh-pages'; then
172+
echo "Creating gh-pages branch"
173+
git checkout --orphan gh-pages
174+
git reset --hard
175+
git commit --allow-empty -m "Initialize gh-pages branch"
176+
git push origin gh-pages
177+
178+
# Try to go back to original branch
179+
if git checkout ${CURRENT_BRANCH}; then
180+
echo "Returned to ${CURRENT_BRANCH} branch"
181+
elif git checkout main; then
182+
echo "Returned to main branch"
183+
elif git checkout master; then
184+
echo "Returned to master branch"
185+
else
186+
echo "Warning: Could not return to original branch, using default branch"
187+
git checkout $(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
188+
fi
189+
190+
echo "Created gh-pages branch successfully"
191+
else
192+
echo "gh-pages branch already exists"
193+
fi
128194
129195
- name: Set up Helm
130196
uses: azure/setup-helm@v3
131197
with:
132198
version: 'latest'
133199

134-
- name: Push Helm chart to OCI registry
200+
- name: Add dependency repositories
201+
run: |
202+
helm repo add bitnami https://charts.bitnami.com/bitnami
203+
helm repo update
204+
205+
- name: Display chart version
206+
run: |
207+
echo "Using chart version: ${{ needs.extract-versions.outputs.chart_version }}"
208+
echo "Using app version: ${{ needs.extract-versions.outputs.app_version }}"
209+
210+
- name: Update chart version
211+
run: |
212+
# Update Chart.yaml with the version from earlier steps
213+
sed -i "s/^version:.*/version: ${{ needs.extract-versions.outputs.chart_version }}/" deploy/quix-environment-operator/Chart.yaml
214+
sed -i "s/^appVersion:.*/appVersion: \"${{ needs.extract-versions.outputs.app_version }}\"/" deploy/quix-environment-operator/Chart.yaml
215+
echo "Updated chart version to ${{ needs.extract-versions.outputs.chart_version }}"
216+
cat deploy/quix-environment-operator/Chart.yaml
217+
218+
- name: Verify values.yaml image tag
219+
run: |
220+
# Ensure values.yaml has the correct image tag
221+
echo "Verifying values.yaml image tag..."
222+
if grep -q "tag: \"latest\"" deploy/quix-environment-operator/values.yaml; then
223+
echo "Updating values.yaml with image tag: ${{ needs.extract-versions.outputs.app_version }}"
224+
sed -i "s/tag: \"latest\"/tag: \"${{ needs.extract-versions.outputs.app_version }}\"/" deploy/quix-environment-operator/values.yaml
225+
fi
226+
echo "Current values.yaml image configuration:"
227+
cat deploy/quix-environment-operator/values.yaml | grep -A 3 "image:"
228+
229+
- name: Create config file
135230
run: |
136-
echo "${{ secrets.DOCKERHUB_TOKEN }}" | helm registry login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin registry-1.docker.io
137-
helm push ./deploy/quix-environment-operator-${{ needs.extract-versions.outputs.chart_version }}.tgz ${{ env.HELM_REGISTRY }}
138-
echo "Helm chart pushed successfully"
231+
cat > cr.yaml <<EOF
232+
index-path: ./index.yaml
233+
charts-repo: https://quixio.github.io/quix-environment-operator/
234+
pages-branch: gh-pages
235+
# Use direct URL format without extra directory level
236+
chart-url-template: "https://quixio.github.io/quix-environment-operator/{{ .Name }}-{{ .Version }}.tgz"
237+
package-path: .cr-release-packages
238+
EOF
239+
240+
- name: Run chart-releaser
241+
uses: helm/[email protected]
242+
with:
243+
charts_dir: deploy
244+
config: cr.yaml
245+
env:
246+
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
247+
CR_SKIP_EXISTING: "true"
248+
CR_FORCE: "true"
249+
CR_PAGES_BRANCH: "gh-pages"
250+
251+
- name: Fallback - Manual Chart Publishing
252+
if: failure()
253+
run: |
254+
echo "Chart-releaser action failed, using manual approach"
255+
256+
# Make sure we're not on gh-pages branch
257+
if [[ $(git branch --show-current) == "gh-pages" ]]; then
258+
echo "Currently on gh-pages branch, switching back to source branch"
259+
260+
# Remember original branch/ref
261+
GITHUB_REF_NAME="${GITHUB_REF_NAME:-main}"
262+
echo "Attempting to return to branch: ${GITHUB_REF_NAME}"
263+
264+
# Try different branches in order
265+
if git fetch origin ${GITHUB_REF_NAME} && git checkout ${GITHUB_REF_NAME}; then
266+
echo "Returned to ${GITHUB_REF_NAME} branch"
267+
elif git fetch origin main && git checkout main; then
268+
echo "Returned to main branch"
269+
else
270+
# As a last resort, get the default branch from the remote
271+
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5)
272+
git fetch origin ${DEFAULT_BRANCH}
273+
git checkout ${DEFAULT_BRANCH}
274+
echo "Returned to ${DEFAULT_BRANCH} branch"
275+
fi
276+
fi
277+
278+
# Save the source branch name
279+
SOURCE_BRANCH=$(git branch --show-current)
280+
echo "Current branch: ${SOURCE_BRANCH}"
281+
282+
# Package the chart while on source branch
283+
mkdir -p .cr-release-packages
284+
285+
# Make sure charts dir exists and package before switching branch
286+
if [ -d "deploy/quix-environment-operator" ]; then
287+
helm package deploy/quix-environment-operator -d .cr-release-packages
288+
else
289+
# Fallback to look for the chart elsewhere
290+
find . -name Chart.yaml -exec dirname {} \; | while read chart_dir; do
291+
echo "Found chart at: ${chart_dir}"
292+
helm package ${chart_dir} -d .cr-release-packages
293+
done
294+
fi
295+
296+
# Make sure we actually packaged something
297+
if [ ! "$(ls -A .cr-release-packages)" ]; then
298+
echo "Error: No charts were packaged"
299+
exit 1
300+
fi
301+
302+
# Get chart filename
303+
CHART_FILE=$(basename $(find .cr-release-packages -name "*.tgz"))
304+
echo "Chart file: ${CHART_FILE}"
305+
306+
# Clone gh-pages branch
307+
git fetch origin gh-pages
308+
git checkout gh-pages
309+
310+
# Copy packaged chart
311+
cp .cr-release-packages/*.tgz .
312+
313+
# Create or update the Helm repo index file on gh-pages
314+
# Important: Use the URL that refers directly to files in gh-pages, not GitHub releases
315+
if [ -f "index.yaml" ]; then
316+
# Update existing index
317+
helm repo index --url https://quixio.github.io/quix-environment-operator/ --merge index.yaml .
318+
else
319+
# Create new index
320+
helm repo index --url https://quixio.github.io/quix-environment-operator/ .
321+
fi
322+
323+
# Commit and push to gh-pages
324+
git add .
325+
git commit -m "Update Helm chart release [skip ci]"
326+
git push origin gh-pages
327+
328+
echo "Manually published chart to GitHub Pages at https://quixio.github.io/quix-environment-operator/${CHART_FILE}"
329+
330+
#Whitespace

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
215215
.PHONY: helm-package
216216
helm-package: ## Package the Helm chart.
217217
@echo "Packaging Helm chart..."
218-
@mkdir -p helm/quix-environment-operator/charts
218+
@mkdir -p ./helm
219219
@helm package ./deploy/quix-environment-operator -d ./helm
220220

221221
.PHONY: helm-lint

0 commit comments

Comments
 (0)