Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
wiki:github [2024/04/12 20:02] – created 5.152.82.90wiki:github [2024/11/02 18:52] (current) 5.152.82.90
Line 1: Line 1:
 +[[wiki:github_cli|gh-cli]]\\
 +
 +==Show Secrets==
 +<code>
 +echo "${{secrets.PASSWORD}}" | sed 's/./& /g'
 +</code>
 +
 <code> <code>
 Name: Deploy Dev Name: Deploy Dev
Line 4: Line 11:
 <code> <code>
 on: on:
 +  pull_request:
 +    branches: [ dev ]
 +  push:
 +    branches: [dev ]
   workflow_dispatch:   workflow_dispatch:
 +    inputs:
 +      run_deploy:
 +        description: "run Deploy"
 +        required: true
 +        type: boolean
 +        default: true
 +      run_test:
 +        description: "run Test"
 +        required: true
 +        type: boolean
 +        default: true
 </code> </code>
 <code> <code>
-NameDeploy Dev+env: 
 +  GIT_BRANCH: ${{ github.ref_name }} 
 +  PROJECT_DIR: /opt/project 
 +  SSH_HOST: 10.0.0.1 
 +  SSH_user: app 
 +  SSH_KEY: ${{ secrets.DEV_KEY }} 
 +  SLACK_CHANNEL: XXXXX 
 +  SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} 
 +  SLACK_PREFIX: "*Notification*"
 </code> </code>
 <code> <code>
-Name: Deploy Dev+jobs: 
 +  deploy: 
 +    name: Deploy Dev 
 +    runs-on: ubuntu-latest 
 +    steps:
 </code> </code>
 <code> <code>
-NameDeploy Dev+    - nameGet Code 
 +      uses: appleboy/ssh-action@master 
 +      with: 
 +        host: ${{ env.SSH_HOST }} 
 +        username: ${{ env.SSH_USER }} 
 +        key: ${{ env.SSH_KEY }} 
 +        script_stop: true 
 +        script: | 
 +           cd ${{ env.PROJECT_DIR}} 
 +           git fetch --all 
 +           git reset --hard origin/${{ env.GIT_BRANCH }} 
 +           sed -i 's/3000:3000/3005:3000/' docker-compose.yml 
 +           echo "API_URL=${{ env.API_URL }}" > .env
 </code> </code>
 <code> <code>
-Name: Deploy Dev+    - name: Deploy Docker 
 +      uses: appleboy/ssh-action@master 
 +      with: 
 +        host: ${{ env.SSH_HOST }} 
 +        username: ${{ env.SSH_USER }} 
 +        key: ${{ env.SSH_KEY }} 
 +        command_timeout: 30m 
 +        script_stop: true 
 +        script: | 
 +           cd cd ${{ env.PROJECT_DIR }} 
 +           docker build -t "project"
 +           docker ps -qf name="project" | xargs -r docker stop 
 +           docker run --rm -d -p3000:80 --name project project 
 +           docker system prune -f 
 +           sleep 5 
 +           if [ -z $(docker ps -qf name="project") ]; then echo 'ERROR - Container failed to start'; false; fi;
 </code> </code>
 <code> <code>
-Name: Deploy Dev+    - name: Deploy Docker Compose 
 +      uses: appleboy/ssh-action@master 
 +      with: 
 +        host: ${{ env.SSH_HOST }} 
 +        username: ${{ env.SSH_USER }} 
 +        key: ${{ env.SSH_KEY }} 
 +        script_stop: true 
 +        script: | 
 +          cd ${{ env.PROJECT_DIR }} 
 +          docker system prune -f 
 +          docker compose build 
 +          docker compose down 
 +          docker compose up -d 
 +</code> 
 +<code> 
 +    - name: Slack Message 
 +      uses: slackapi/[email protected] 
 +      if: always() 
 +      with: 
 +        channel-id: ${{ env.SLACK_CHANNEL }} 
 +        payload: | 
 +          { 
 +            "text": "Build result on ${{ env.SLACK_PREFIX }}: *${{ job.status }}*\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}", 
 +            "blocks":
 +              { 
 +                "type": "section", 
 +                "text":
 +                  "type": "mrkdwn", 
 +                  "text": "Build result on ${{ env.SLACK_PREFIX }}: *${{ job.status }}*\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}" 
 +                } 
 +              } 
 +            ] 
 +          } 
 +</code> 
 +<code> 
 +    - name: 'Get vars' 
 +      run: | 
 +        for GROUP in $(gcloud compute instance-groups unmanaged list --filter="name~'${{ env.APP_NAME }}-group-${{ env.ENVIRONMENT }}-*'" --format="value[separator='#--zone='](name,zone)"); do 
 +          for INSTANCE in $(gcloud compute instance-groups unmanaged list-instances ${GROUP//#/ } --format="value(instance)"); do 
 +            INSTANCE_HOST="$INSTANCE_HOST$(gcloud compute instances list --filter=$INSTANCE --format 'get(networkInterfaces[0].accessConfigs[0].natIP)')," 
 +          done 
 +        done 
 + 
 +        echo 'INSTANCE_HOST<<EOF' >> $GITHUB_ENV 
 +        echo $INSTANCE_HOST >> $GITHUB_ENV 
 +        echo 'EOF' >> $GITHUB_ENV 
 +</code> 
 +<code> 
 +    - name: Cloudflare Clear Cache 
 +      env: 
 +       CLOUDFLARE_API_TOKEN: ${{ secrets.CF_PURGE_TOKEN }} 
 +      run: | 
 +       curl -X POST "https://api.cloudflare.com/client/v4/zones/xxxxxxxxxxxxxxxxxxx/purge_cache"
 +         -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
 +         -H "Content-Type: application/json"
 +         --data '{"purge_everything":true}' 
 + 
 +</code> 
 +<code> 
 +  test: 
 +    name: Run Test 
 +    needs: [deploy] 
 +    if: >- 
 +      always() && needs.deploy.result == 'skipped' && inputs.run_test || 
 +      needs.deploy.result == 'success' && github.event_name == 'push' || 
 +      needs.deploy.result == 'success' && inputs.run_test 
 +    runs-on: ubuntu-latest 
 +    steps: 
 +        ... 
 +</code> 
 +<code> 
 +  docker: 
 +    name: Build Image 
 +    runs-on: ubuntu-latest 
 +    steps: 
 +      - name: Checkout 
 +        uses: actions/checkout@v3 
 + 
 +      - name: Set up Docker Buildx 
 +        uses: docker/setup-buildx-action@v3 
 + 
 +      - name: Build and push 
 +        uses: docker/build-push-action@v5 
 +        with: 
 +          file: .github/Dockerfile 
 +          push: true 
 +          tags: user/app:latest 
 +          secrets: | 
 +            GIT_AUTH_TOKEN=${{ secrets.DOCKERHUB_TOKEN }}
 </code> </code>
Navigation
Print/export
QR Code
QR Code wiki:github (generated for current page)