commit 575487fec888c99a8cc4d492a3f3b120d0e90ab5 Author: admin Date: Tue May 26 06:59:37 2026 +0000 Upload files to "/" diff --git a/ci(1).yml b/ci(1).yml new file mode 100644 index 0000000..7444671 --- /dev/null +++ b/ci(1).yml @@ -0,0 +1,75 @@ +name: CI - Build and Push Docker Image +on: + push: + branches: ["main", "master"] + workflow_dispatch: + +jobs: + docker-build-push: + runs-on: docker-build + outputs: + image_ref: ${{ steps.vars.outputs.image_ref }} + image_branch_tag: ${{ steps.vars.outputs.image_branch_tag }} + steps: + - name: Checkout source + uses: http://${{ secrets.READ_REPOSITORY_TOKEN }}@gitea.rellet.ir/mirrors/actions-checkout@4.3.1 + + - name: Prepare vars + id: vars + run: | + REGISTRY="gitea.rellet.ir" + IMAGE="${GITHUB_REPOSITORY,,}" + TAG_SHORT="${GITHUB_SHA:0:7}" + TAG_BRANCH="${GITHUB_REF_NAME}" + + echo "REGISTRY=$REGISTRY" >> $GITHUB_ENV + echo "IMAGE=$IMAGE" >> $GITHUB_ENV + echo "TAG_SHORT=$TAG_SHORT" >> $GITHUB_ENV + echo "TAG_BRANCH=$TAG_BRANCH" >> $GITHUB_ENV + + # Export to downstream jobs so deploy doesn't rebuild the string + echo "image_ref=$REGISTRY/$IMAGE:$TAG_SHORT" >> $GITHUB_OUTPUT + echo "image_branch_tag=$REGISTRY/$IMAGE:$TAG_BRANCH" >> $GITHUB_OUTPUT + + - name: Login to registries + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login 127.0.0.1:3000 -u "${{ secrets.REGISTRY_USER }}" --password-stdin + echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login gitea.rellet.ir -u "${{ secrets.REGISTRY_USER }}" --password-stdin + + - name: Build and Push + run: | + docker buildx build \ + --file test-worker-1/Dockerfile \ + -t $REGISTRY/$IMAGE:$TAG_SHORT \ + -t $REGISTRY/$IMAGE:$TAG_BRANCH \ + --push \ + . + + deploy: + runs-on: docker-build + needs: docker-build-push + if: github.ref_name == 'main' || github.ref_name == 'master' + steps: + - name: Deploy to server + uses: http://${{ secrets.READ_REPOSITORY_TOKEN }}@gitea.rellet.ir/mirrors/appleboy-ssh-action@1.2.7 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: ${{ secrets.SSH_PORT || '22' }} + script: | + IMAGE="${{ needs.docker-build-push.outputs.image_ref }}" + + echo "Pulling $IMAGE" + docker pull $IMAGE + + echo "Stopping old container" + docker stop test-worker-1 || true + docker rm test-worker-1 || true + + echo "Starting new worker container" + docker run -d \ + --name test-worker-1 \ + --restart unless-stopped \ + -e DOTNET_ENVIRONMENT=Production \ + $IMAGE \ No newline at end of file