|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: [published] |
| 5 | +jobs: |
| 6 | + push_to_registry: |
| 7 | + runs-on: ubuntu-20.04 |
| 8 | + steps: |
| 9 | + - name: checkout |
| 10 | + uses: actions/checkout@v2 |
| 11 | + |
| 12 | + - name: dotnet publish |
| 13 | + run: | |
| 14 | + dotnet publish ./ParcelTemplate/ -o publish -c release |
| 15 | + |
| 16 | + - name: repository name fix |
| 17 | + run: echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 18 | + |
| 19 | + - name: Login to GitHub Container Registry |
| 20 | + uses: docker/login-action@v1 |
| 21 | + with: |
| 22 | + registry: ghcr.io |
| 23 | + username: ${{ github.repository_owner }} |
| 24 | + password: ${{ secrets.CR_PAT }} |
| 25 | + |
| 26 | + - name: Build and push Docker images |
| 27 | + |
| 28 | + with: |
| 29 | + file: ParcelTemplate/Dockerfile |
| 30 | + context: . |
| 31 | + push: true |
| 32 | + tags: ghcr.io/${{ env.image_repository_name }}:${{ github.event.release.tag_name }} |
| 33 | + |
| 34 | + deploy_via_ssh: |
| 35 | + needs: push_to_registry |
| 36 | + runs-on: ubuntu-20.04 |
| 37 | + steps: |
| 38 | + - name: checkout |
| 39 | + uses: actions/checkout@v2 |
| 40 | + |
| 41 | + - name: repository name fix and env |
| 42 | + run: | |
| 43 | + echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 44 | + echo "domain=${{ secrets.DEPLOY_HOST }}" >> $GITHUB_ENV |
| 45 | + echo "letsencrypt_email=${{ secrets.LETSENCRYPT_EMAIL }}" >> $GITHUB_ENV |
| 46 | +
|
| 47 | + - name: docker-compose file prep |
| 48 | + uses: danielr1996/[email protected] |
| 49 | + env: |
| 50 | + RELEASE_VERSION: ${{ github.event.release.tag_name }} |
| 51 | + IMAGE_REPO: ${{ env.image_repository_name }} |
| 52 | + HOST_DOMAIN: ${{ env.domain }} |
| 53 | + LETSENCRYPT_EMAIL: ${{ env.letsencrypt_email }} |
| 54 | + with: |
| 55 | + input: deploy/docker-compose-template.yml |
| 56 | + output: deploy/ParcelTemplate-docker-compose.yml |
| 57 | + |
| 58 | + - name: copy compose file via scp |
| 59 | + |
| 60 | + with: |
| 61 | + host: ${{ secrets.DEPLOY_HOST }} |
| 62 | + username: ${{ secrets.DEPLOY_USERNAME }} |
| 63 | + port: ${{ secrets.DEPLOY_PORT }} |
| 64 | + key: ${{ secrets.DEPLOY_KEY }} |
| 65 | + source: "deploy/ParcelTemplate-docker-compose.yml" |
| 66 | + target: "~/" |
| 67 | + |
| 68 | + - name: Set the value |
| 69 | + run: | |
| 70 | + echo "GH_TOKEN=${{ secrets.CR_PAT }}" >> $GITHUB_ENV |
| 71 | + echo "USERNAME=${{ secrets.DEPLOY_USERNAME }}" >> $GITHUB_ENV |
| 72 | +
|
| 73 | + - name: remote docker-compose up via ssh |
| 74 | + |
| 75 | + env: |
| 76 | + APPTOKEN: ${{ env.GH_TOKEN }} |
| 77 | + USERNAME: ${{ env.USERNAME }} |
| 78 | + with: |
| 79 | + host: ${{ secrets.DEPLOY_HOST }} |
| 80 | + username: ${{ secrets.DEPLOY_USERNAME }} |
| 81 | + key: ${{ secrets.DEPLOY_KEY }} |
| 82 | + port: ${{ secrets.DEPLOY_PORT }} |
| 83 | + envs: APPTOKEN,USERNAME |
| 84 | + script: | |
| 85 | + echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin |
| 86 | + docker-compose -f ~/deploy/ParcelTemplate-docker-compose.yml up -d |
0 commit comments