Skip to content

Commit

Permalink
update helm repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujstor committed May 8, 2024
1 parent bd4e847 commit 64d4f87
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ jobs:
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Run docker tag sh and export var form config.yml
- name: Run docker tag sh and export var from config.yml
run: |
./docker_tag.sh
- uses: cardinalby/export-env-action@v2
- name: Export env variabels
uses: cardinalby/export-env-action@v2
with:
envFile: '.env'

Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/update-helm-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Update helm repo

on:
workflow_run:
workflows: ["Publish Docker image"]
types:
- completed
jobs:
update-helm-repo:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Export var from config.yml
run: |
./latest_tag.sh
- name: Export env variabels
uses: cardinalby/export-env-action@v2
with:
envFile: '.env'

- name: Checkout helm repo
uses: actions/checkout@v4
with:
repository: ${{ env.REPO }}

- name: Update chart values.yaml
run : |
sudo yq -i '.deployment.tag = strenv(${{ env.LATEST_TAG }})' ${{ env.CHART }}/values.yaml
- name: Debug
run: |
cat ${{ env.CHART }}/values.yaml
- name: Push changes to chart repo
run: |
git config --global user.email "<EMAIL>"
git config --global user.name "GitHub Action"
git add ${{ env.CHART }}/values.yaml
git commit -m "Update deployment image tag to ${{ env.LATEST_TAG }}"
git push -f origin master
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GitHub Actions for ArgoCD CICD pipeline
# GitHub Actions Workflow for ArgoCD CICD pipeline

![pipline](public/pipeline.png)

Expand All @@ -10,14 +10,19 @@ Dependencies:
- [yq](https://github.com/mikefarah/yq)
- [jq](https://github.com/jqlang/jq)

variables are defined in `config.yml`
Variables are defined in `config.yml` and can be updated upon commit for new image tag:

```yaml
docker:
DOCKER_HUB_USERNAME:
DOCKER_REPO_NAME:
VERSION_PART: # Patch, Minor, Major
```
If the image does not exist, the default image tag is 0.0.1. Semantic versioning is employed upon commit, automatically incrementing the version
Default image tag if image does not exist is 0.0.1
On commit semantic versioning is used and the version is autmatically incremented
Workflow also requires DockerHub login credentials, username and password configuration in the Action secret:
```yaml
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
```
5 changes: 5 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ docker:
DOCKER_HUB_USERNAME: ujstor
DOCKER_REPO_NAME: argocd-test
VERSION_PART: Patch # Patch, Minor, major

github-helm-repo:
REPO: Ujstor/argoCD-test-helm
CHART: http-server

21 changes: 21 additions & 0 deletions latest_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

eval $(yq e '.docker | to_entries | .[] | "export \(.key)=\(.value)"' config.yml)
eval $(yq e '.github-helm-repo | to_entries | .[] | "export \(.key)=\(.value)"' config.yml)

DOCKER_IMAGE="$DOCKER_HUB_USERNAME/$DOCKER_REPO_NAME"

TAGS=$(curl -s "https://hub.docker.com/v2/repositories/$DOCKER_IMAGE/tags/?page_size=100" | jq -r '.results[].name')

LATEST_TAG=$(echo "$TAGS" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)


create_env_file() {
cat << EOF > .env
LATEST_TAG=$LATEST_TAG
REPO=$REPO
CHART=$CHART
EOF
}

create_env_file
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func handler(w http.ResponseWriter, r *http.Request) {
html := `<html><head><title>Test1</title></head><body><h1>Welcome to Test1</h1></body></html>`
html := `<html><head><title>Test2</title></head><body><h1>Welcome to Test1</h1></body></html>`
_, err := w.Write([]byte(html))
if err != nil {
http.Error(w, "Error writing response", http.StatusInternalServerError)
Expand Down

0 comments on commit 64d4f87

Please sign in to comment.