|
| 1 | +# This workflow uses actions that are not certified by GitHub. |
| 2 | +# They are provided by a third-party and are governed by separate terms of service, |
| 3 | +# privacy policy, and support documentation. |
| 4 | +# |
| 5 | +# This workflow will build and publish a Docker container which is then deployed through Octopus Deploy. |
| 6 | +# |
| 7 | +# The build job in this workflow currently assumes that there is a Dockerfile that generates the relevant application image. |
| 8 | +# If required, this job can be modified to generate whatever alternative build artifact is required for your deployment. |
| 9 | +# |
| 10 | +# This workflow assumes you have already created a Project in Octopus Deploy. |
| 11 | +# For instructions see https://octopus.com/docs/projects/setting-up-projects |
| 12 | +# |
| 13 | +# To configure this workflow: |
| 14 | +# |
| 15 | +# 1. Decide where you are going to host your image. |
| 16 | +# This template uses the GitHub Registry for simplicity but if required you can update the relevant DOCKER_REGISTRY variables below. |
| 17 | +# |
| 18 | +# 2. Create and configure an OIDC credential for a service account in Octopus. |
| 19 | +# This allows for passwordless authentication to your Octopus instance through a trust relationship configured between Octopus, GitHub and your GitHub Repository. |
| 20 | +# https://octopus.com/docs/octopus-rest-api/openid-connect/github-actions |
| 21 | +# |
| 22 | +# 3. Configure your Octopus project details below: |
| 23 | +# OCTOPUS_URL: update to your Octopus Instance Url |
| 24 | +# OCTOPUS_SERVICE_ACCOUNT: update to your service account Id |
| 25 | +# OCTOPUS_SPACE: update to the name of the space your project is configured in |
| 26 | +# OCTOPUS_PROJECT: update to the name of your Octopus project |
| 27 | +# OCTOPUS_ENVIRONMENT: update to the name of the environment to recieve the first deployment |
| 28 | + |
| 29 | + |
| 30 | +name: 'Build and Deploy to Octopus Deploy' |
| 31 | + |
| 32 | +on: |
| 33 | + push: |
| 34 | + branches: |
| 35 | + - '"master"' |
| 36 | + |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + name: Build |
| 40 | + runs-on: ubuntu-latest |
| 41 | + permissions: |
| 42 | + packages: write |
| 43 | + contents: read |
| 44 | + env: |
| 45 | + DOCKER_REGISTRY: ghcr.io # TODO: Update to your docker registry uri |
| 46 | + DOCKER_REGISTRY_USERNAME: ${{ github.actor }} # TODO: Update to your docker registry username |
| 47 | + DOCKER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} # TODO: Update to your docker registry password |
| 48 | + outputs: |
| 49 | + image_tag: ${{ steps.meta.outputs.version }} |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - name: Set up Docker Buildx |
| 54 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 55 | + |
| 56 | + - name: Log in to the Container registry |
| 57 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 58 | + with: |
| 59 | + registry: ${{ env.DOCKER_REGISTRY }} |
| 60 | + username: ${{ env.DOCKER_REGISTRY_USERNAME }} |
| 61 | + password: ${{ env.DOCKER_REGISTRY_PASSWORD }} |
| 62 | + |
| 63 | + - name: Extract metadata (tags, labels) for Docker |
| 64 | + id: meta |
| 65 | + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
| 66 | + with: |
| 67 | + images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository }} |
| 68 | + tags: type=semver,pattern={{version}},value=v1.0.0-{{sha}} |
| 69 | + |
| 70 | + - name: Build and push Docker image |
| 71 | + id: push |
| 72 | + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 |
| 73 | + with: |
| 74 | + context: . |
| 75 | + push: true |
| 76 | + tags: ${{ steps.meta.outputs.tags }} |
| 77 | + labels: ${{ steps.meta.outputs.labels }} |
| 78 | + deploy: |
| 79 | + name: Deploy |
| 80 | + permissions: |
| 81 | + id-token: write |
| 82 | + runs-on: ubuntu-latest |
| 83 | + needs: [ build ] |
| 84 | + env: |
| 85 | + OCTOPUS_URL: 'https://your-octopus-url' # TODO: update to your Octopus Instance url |
| 86 | + OCTOPUS_SERVICE_ACCOUNT: 'your-service-account-id' # TODO: update to your service account Id |
| 87 | + OCTOPUS_SPACE: 'your-space' # TODO: update to the name of the space your project is configured in |
| 88 | + OCTOPUS_PROJECT: 'your-project' # TODO: update to the name of your Octopus project |
| 89 | + OCTOPUS_ENVIRONMENT: 'your-environment' # TODO: update to the name of the environment to recieve the first deployment |
| 90 | + |
| 91 | + steps: |
| 92 | + - name: Log in to Octopus Deploy |
| 93 | + uses: OctopusDeploy/login@34b6dcc1e86fa373c14e6a28c5507d221e4de629 #v1.0.2 |
| 94 | + with: |
| 95 | + server: '${{ env.OCTOPUS_URL }}' |
| 96 | + service_account_id: '${{ env.OCTOPUS_SERVICE_ACCOUNT }}' |
| 97 | + |
| 98 | + - name: Create Release |
| 99 | + id: create_release |
| 100 | + uses: OctopusDeploy/create-release-action@fea7e7b45c38c021b6bc5a14bd7eaa2ed5269214 #v3.2.2 |
| 101 | + with: |
| 102 | + project: '${{ env.OCTOPUS_PROJECT }}' |
| 103 | + space: '${{ env.OCTOPUS_SPACE }}' |
| 104 | + packages: '*:${{ needs.build.outputs.image_tag }}' |
| 105 | + |
| 106 | + - name: Deploy Release |
| 107 | + uses: OctopusDeploy/deploy-release-action@b10a606c903b0a5bce24102af9d066638ab429ac #v3.2.1 |
| 108 | + with: |
| 109 | + project: '${{ env.OCTOPUS_PROJECT }}' |
| 110 | + space: '${{ env.OCTOPUS_SPACE }}' |
| 111 | + release_number: '${{ steps.create_release.outputs.release_number }}' |
| 112 | + environments: ${{ env.OCTOPUS_ENVIRONMENT }} |
0 commit comments