From c20251307420aa87c9fd93932eb66d0de4f49a32 Mon Sep 17 00:00:00 2001 From: xyzuan Date: Tue, 5 Nov 2024 10:24:15 +0700 Subject: [PATCH] misc(ci/cd): Update dev action --- .github/workflows/build-dev.yml | 37 +++++++++++++++++--------------- .github/workflows/build-prod.yml | 2 +- misc/Dockerfile.dev | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index bfb12a2..cc2283d 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -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/ssh-agent@v0.9.0 @@ -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 }} \ @@ -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: | @@ -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 diff --git a/.github/workflows/build-prod.yml b/.github/workflows/build-prod.yml index 78fc05c..f37f731 100644 --- a/.github/workflows/build-prod.yml +++ b/.github/workflows/build-prod.yml @@ -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/ssh-agent@v0.9.0 diff --git a/misc/Dockerfile.dev b/misc/Dockerfile.dev index e368db4..345a019 100644 --- a/misc/Dockerfile.dev +++ b/misc/Dockerfile.dev @@ -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"]