Skip to content

Commit 494dbd0

Browse files
committed
refactor(cd): reemplazar tags de deploy por git SHA de 7 caracteres
1 parent 12f6fdb commit 494dbd0

1 file changed

Lines changed: 2 additions & 35 deletions

File tree

.github/workflows/cd.yaml

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ on:
66
types: [completed]
77
branches: [master]
88

9-
permissions:
10-
contents: write
11-
129
env:
1310
OCIR_REGISTRY: mx-queretaro-1.ocir.io
1411
IMAGE_REPOSITORY: mx-queretaro-1.ocir.io/axjlbcwfm44q/reacttodo/wx7u0/todolistapp-springboot
1512
K8S_NAMESPACE: mtdrworkshop
1613
K8S_DEPLOYMENT: todolistapp-springboot-deployment
1714
K8S_CONTAINER: todolistapp-springboot
18-
INITIAL_DEPLOY_MINOR_VERSION: '10'
1915

2016
jobs:
2117
deploy:
@@ -31,33 +27,6 @@ jobs:
3127
- uses: actions/checkout@v4
3228
with:
3329
ref: ${{ github.event.workflow_run.head_branch }}
34-
fetch-depth: 0
35-
36-
- name: Calculate next image version
37-
id: version
38-
shell: bash
39-
run: |
40-
latest_tag="$(git tag -l 'deploy-0.*' --sort=-v:refname | head -n 1)"
41-
42-
if [ -z "$latest_tag" ]; then
43-
current_minor="${INITIAL_DEPLOY_MINOR_VERSION}"
44-
else
45-
current_minor="${latest_tag#deploy-0.}"
46-
fi
47-
48-
next_minor=$((current_minor + 1))
49-
image_tag="0.${next_minor}"
50-
51-
echo "image_tag=${image_tag}" >> "$GITHUB_OUTPUT"
52-
echo "git_tag=deploy-${image_tag}" >> "$GITHUB_OUTPUT"
53-
54-
- name: Register deployed version tag
55-
shell: bash
56-
run: |
57-
git config user.name "github-actions[bot]"
58-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59-
git tag "${{ steps.version.outputs.git_tag }}"
60-
git push origin "${{ steps.version.outputs.git_tag }}"
6130

6231
- name: Log in to OCIR
6332
uses: docker/login-action@v3
@@ -67,9 +36,8 @@ jobs:
6736
password: ${{ secrets.OCIR_PASSWORD }}
6837

6938
- name: Build and Push Docker image
70-
env:
71-
IMAGE_TAG: ${{ steps.version.outputs.image_tag }}
7239
run: |
40+
IMAGE_TAG="${GITHUB_SHA:0:7}"
7341
docker build -f MtdrSpring/backend/Dockerfile -t "$IMAGE_REPOSITORY:$IMAGE_TAG" MtdrSpring/backend/
7442
docker push "$IMAGE_REPOSITORY:$IMAGE_TAG"
7543
@@ -80,9 +48,8 @@ jobs:
8048
chmod 600 ~/.kube/config
8149
8250
- name: Deploy to Kubernetes (OKE)
83-
env:
84-
IMAGE_TAG: ${{ steps.version.outputs.image_tag }}
8551
run: |
52+
IMAGE_TAG="${GITHUB_SHA:0:7}"
8653
kubectl set image deployment/"$K8S_DEPLOYMENT" "$K8S_CONTAINER"="$IMAGE_REPOSITORY":"$IMAGE_TAG" -n "$K8S_NAMESPACE"
8754
kubectl rollout status deployment/"$K8S_DEPLOYMENT" -n "$K8S_NAMESPACE" --timeout=180s
8855
kubectl get pods -n "$K8S_NAMESPACE"

0 commit comments

Comments
 (0)