Skip to content

Commit

Permalink
misc(ci/cd): fix ct naming with gh_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzuan committed Nov 5, 2024
1 parent 2cae2ca commit 4617113
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
26 changes: 15 additions & 11 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
push:
branches:
- dev
# pull_request:
# branches:
# - main

jobs:
build:
Expand All @@ -19,6 +16,13 @@ jobs:
- name: Settle up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Declaring some Global Environtment vars
run: |
BRANCH_NAME=${GITHUB_REF##*/}
SHA=$(echo "$GITHUB_SHA" | head -c 7)
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
echo "SHA=${SHA}" >> $GITHUB_ENV
- name: Authenticating to Eden Server realms.
uses: webfactory/ssh-agent@v0.9.0
with:
Expand Down Expand Up @@ -46,17 +50,17 @@ jobs:
--build-arg CLOUDINARY_CLOUD_NAME=${{ secrets.CLOUDINARY_CLOUD_NAME }} \
--build-arg CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }} \
--build-arg CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }} \
-t ghcr.io/xyzuan/xyzuan_api_v2:dev -f misc/Dockerfile.dev .
-t ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME} -f misc/Dockerfile.dev .
- name: Adding tags to the Images
run: |
IMAGE_NAME=ghcr.io/xyzuan/xyzuan_api_v2
docker tag $IMAGE_NAME:dev $IMAGE_NAME:$(echo "${{ github.sha }}" | head -c 7)
docker tag $IMAGE_NAME:${BRANCH_NAME} $IMAGE_NAME:${SHA}
- name: Bring the Images to GHCR
run: |
docker push ghcr.io/xyzuan/xyzuan_api_v2:dev
docker push ghcr.io/xyzuan/xyzuan_api_v2:$(echo "${{ github.sha }}" | head -c 7)
docker push ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME}
docker push ghcr.io/xyzuan/xyzuan_api_v2:${SHA}
- name: Serving the Images in Eden Server realms.
run: |
Expand All @@ -67,16 +71,16 @@ jobs:
echo "${{ secrets.GH_TOKEN }}" | docker login -u "${{ github.actor }}" ghcr.io --password-stdin
echo 'Pulling the latest image from GHCR...'
docker pull ghcr.io/xyzuan/xyzuan_api_v2:dev
docker pull ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME}
echo 'Force Blowing the exist Docker Container...'
docker rm -f xyzuan-api-v2-dev
docker rm -f xyzuan-api-v2-${BRANCH_NAME}
echo 'Running the Docker Container...'
docker run -d \
--name xyzuan-api-v2-dev \
--name xyzuan-api-v2-${BRANCH_NAME} \
--restart always \
--network nginx_default \
-p 3121:3121 \
ghcr.io/xyzuan/xyzuan_api_v2:dev
ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME}
EOF
21 changes: 13 additions & 8 deletions .github/workflows/build-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
- name: Settle up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Declaring some Global vars
run: |
BRANCH_NAME=${GITHUB_REF##*/}
SHA=$(echo "${{ github.sha }}" | head -c 7)
- name: Authenticating to Eden Server realms.
uses: webfactory/ssh-agent@v0.9.0
with:
Expand Down Expand Up @@ -43,17 +48,17 @@ jobs:
--build-arg CLOUDINARY_CLOUD_NAME=${{ secrets.CLOUDINARY_CLOUD_NAME }} \
--build-arg CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }} \
--build-arg CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }} \
-t ghcr.io/xyzuan/xyzuan_api_v2:{{ github.ref }} -f misc/Dockerfile.prod .
-t ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME} -f misc/Dockerfile.prod .
- name: Adding tags to the Images
run: |
IMAGE_NAME=ghcr.io/xyzuan/xyzuan_api_v2
docker tag $IMAGE_NAME:{{ github.ref }} $IMAGE_NAME:$(echo "${{ github.sha }}" | head -c 7)
docker tag $IMAGE_NAME:${BRANCH_NAME} $IMAGE_NAME:${SHA}
- name: Bring the Images to GHCR
run: |
docker push ghcr.io/xyzuan/xyzuan_api_v2:{{ github.ref }}
docker push ghcr.io/xyzuan/xyzuan_api_v2:$(echo "${{ github.sha }}" | head -c 7)
docker push ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME}
docker push ghcr.io/xyzuan/xyzuan_api_v2:${SHA}
- name: Serving the Images in Eden Server realms.
run: |
Expand All @@ -64,16 +69,16 @@ jobs:
echo "${{ secrets.GH_TOKEN }}" | docker login -u "${{ github.actor }}" ghcr.io --password-stdin
echo 'Pulling the latest image from GHCR...'
docker pull ghcr.io/xyzuan/xyzuan_api_v2:{{ github.ref }}
docker pull ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME}
echo 'Force Blowing the exist Docker Container...'
docker rm -f xyzuan-api-v2-{{ github.ref }}
docker rm -f xyzuan-api-v2-{BRANCH_NAME}
echo 'Running the Docker Container...'
docker run -d \
--name xyzuan-api-v2-{{ github.ref }} \
--name xyzuan-api-v2-${BRANCH_NAME} \
--restart always \
--network nginx_default \
-p 3131:3131 \
ghcr.io/xyzuan/xyzuan_api_v2:{{ github.ref }}
ghcr.io/xyzuan/xyzuan_api_v2:${BRANCH_NAME}
EOF

0 comments on commit 4617113

Please sign in to comment.