Skip to content

Commit

Permalink
misc(ci/cd): Update dev action
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzuan committed Nov 5, 2024
1 parent d4d299e commit c202513
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
37 changes: 20 additions & 17 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ jobs:

- 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
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "SHA=$(echo "$GITHUB_SHA" | head -c 7)" >> $GITHUB_ENV
echo "ENV=dev" >> $GITHUB_ENV
echo "PORT=3121" >> $GITHUB_ENV
echo "DOMAIN=xyzuan.my.id" >> $GITHUB_ENV
echo "REGISTRY=ghcr.io/xyzuan" >> $GITHUB_ENV
echo "IMAGE_NAME=xyzuan_api_v2" >> $GITHUB_ENV
echo "DOCKERFILE=misc/Dockerfile.dev" >> $GITHUB_ENV
- name: Authenticating to Eden Server realms.
uses: webfactory/[email protected]
Expand All @@ -34,9 +38,9 @@ jobs:
- name: Treaty Build the Docker image
run: |
docker build \
--build-arg PORT=3121 \
--build-arg NODE_ENV=dev \
--build-arg DOMAIN=xyzuan.my.id \
--build-arg PORT=${{ env.PORT }} \
--build-arg NODE_ENV=${{ env.ENV }} \
--build-arg DOMAIN=${{ env.DOMAIN }} \
--build-arg PASSWORD_PEPPER=${{ secrets.PASSWORD_PEPPER }} \
--build-arg DATABASE_URL=${{ secrets.DATABASE_URL_DEV }} \
--build-arg GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} \
Expand All @@ -50,17 +54,16 @@ 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:${{ env.BRANCH_NAME }} -f misc/Dockerfile.dev .
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }} -f ${{ env.DOCKERFILE }} .
- name: Adding tags to the Images
run: |
IMAGE_NAME=ghcr.io/xyzuan/xyzuan_api_v2
docker tag $IMAGE_NAME:${{ env.BRANCH_NAME }} $IMAGE_NAME:${{env.SHA}}
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }} ${{ env.IMAGE_NAME }}:${{env.SHA}}
- name: Bring the Images to GHCR
run: |
docker push ghcr.io/xyzuan/xyzuan_api_v2:${{ env.BRANCH_NAME }}
docker push ghcr.io/xyzuan/xyzuan_api_v2:${{env.SHA}}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{env.SHA}}
- name: Serving the Images in Eden Server realms.
run: |
Expand All @@ -71,16 +74,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:${{ env.BRANCH_NAME }}
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}
echo 'Force Blowing the exist Docker Container...'
docker rm -f xyzuan-api-v2-${{ env.BRANCH_NAME }}
docker rm -f ${{ env.IMAGE_NAME }}-${{ env.BRANCH_NAME }}
echo 'Running the Docker Container...'
docker run -d \
--name xyzuan-api-v2-${{ env.BRANCH_NAME }} \
--name ${{ env.IMAGE_NAME }}-${{ env.BRANCH_NAME }} \
--restart always \
--network nginx_default \
-p 3121:3121 \
ghcr.io/xyzuan/xyzuan_api_v2:${{ env.BRANCH_NAME }}
-p ${{ env.PORT }}:${{ env.PORT }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}
EOF
2 changes: 1 addition & 1 deletion .github/workflows/build-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
echo "DOMAIN=xyzuan.my.id" >> $GITHUB_ENV
echo "REGISTRY=ghcr.io/xyzuan" >> $GITHUB_ENV
echo "IMAGE_NAME=xyzuan_api_v2" >> $GITHUB_ENV
echo "DOCKERFILE=misc/Dockerfile.dev" >> $GITHUB_ENV
echo "DOCKERFILE=misc/Dockerfile.prod" >> $GITHUB_ENV
- name: Authenticating to Eden Server realms.
uses: webfactory/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion misc/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ENV CLOUDINARY_CLOUD_NAME=$CLOUDINARY_CLOUD_NAME
ENV CLOUDINARY_API_KEY=$CLOUDINARY_API_KEY
ENV CLOUDINARY_API_SECRET=$CLOUDINARY_API_SECRET

EXPOSE 3131
EXPOSE 3121

CMD ["./server"]

0 comments on commit c202513

Please sign in to comment.