Update gh_install.yaml #178
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is a basic workflow to help you get started with Actions | |
| name: Packer Build | |
| # Controls when the workflow will run | |
| on: | |
| # Triggers the workflow on push or pull request events but only for the "main" branch | |
| workflow_dispatch: | |
| push: | |
| branches: [ "main" ] | |
| # A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
| jobs: | |
| # This workflow contains a single job called "build" | |
| build: | |
| # The type of runner that the job will run on | |
| runs-on: ubuntu-latest | |
| env: | |
| PACKER_GITHUB_API_TOKEN: ${{ secrets.GH_TOKEN }} | |
| AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} | |
| # Steps represent a sequence of tasks that will be executed as part of the job | |
| # strategy: | |
| # max-parallel: 1 | |
| # matrix: | |
| # ansible_tag: [terraform, base] | |
| steps: | |
| # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 16 | |
| - uses: actions/checkout@v4 | |
| - name: Setup HashiCorp Packer | |
| # You may pin to the exact commit or the version. | |
| # uses: hashicorp/setup-packer@1aa358be5cf73883762b302a3a03abd66e75b232 | |
| uses: hashicorp/setup-packer@v3.1.0 | |
| - name: Download GTag | |
| run: | | |
| curl -sSL https://raw.githubusercontent.com/HappyPathway/centralized-actions/main/gtag.py -o gtag.py | |
| curl -sSL https://raw.githubusercontent.com/HappyPathway/centralized-actions/main/gtag_requirements.txt -o requirements.txt | |
| - name: setup Python | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: '3.11' | |
| cache: pip | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3.1.2 | |
| with: | |
| terraform_version: 1.9.1 | |
| cli_config_credentials_token: ${{ secrets.TFE_TOKEN }} | |
| cli_config_credentials_hostname: app.terraform.io | |
| terraform_wrapper: false | |
| - name: terraform init | |
| run: terraform init -upgrade -backend-config="bucket=${{ vars.gcs_state_bucket }}" -backend-config="prefix=${{ vars.gcs_state_key }}" | |
| - name: terraform apply | |
| run: terraform apply -auto-approve | |
| - name: terraform output | |
| id: terraform_output | |
| run: echo "respository_uri=$(terraform output repository_uri)" >> $GITHUB_ENV | |
| - name: install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install -r requirements.txt | |
| - name: git fetch --unshallow --tags | |
| run: git fetch --unshallow --tags | |
| - name: get tags | |
| run: git tag --list | |
| - name: GTag | |
| run: | | |
| echo "next_tag=$(python gtag.py --${{ vars.increment_version }})" >> $GITHUB_ENV | |
| - name: Docker Login | |
| # You may pin to the exact commit or the version. | |
| # uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 | |
| uses: docker/login-action@v3.1.0 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USER }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| logout: true | |
| - name: packer init | |
| run: packer init build.pkr.hcl | |
| - name: packer validate | |
| run: | | |
| packer validate \ | |
| -var repository_uri=${{ env.respository_uri }} \ | |
| -var tag=${{ env.next_tag }} \ | |
| -var source_image=${{ vars.source_image }} \ | |
| -var terraform_version=${{ vars.terraform_version }} \ | |
| build.pkr.hcl | |
| - name: set tag | |
| run: | | |
| remote_repo="https://${{vars.gh_username}}:${{secrets.GH_TOKEN}}@${{ vars.gh_server }}/${{ github.repository }}.git" | |
| git remote add repo ${remote_repo} | |
| git config --global user.email "${{vars.gh_email}}" | |
| git config --global user.name "${{vars.gh_username}}" | |
| git tag -a ${{ env.next_tag }} -m "Release ${{ env.next_tag }}" | |
| git push --tags -u repo | |
| # Runs a single command using the runners shell | |
| - name: packer build | |
| run: | | |
| packer build \ | |
| -var repository_uri=${{ env.respository_uri }} \ | |
| -var tag=${{ env.next_tag }} \ | |
| -var source_image=${{ vars.source_image }} \ | |
| -var terraform_version=${{ vars.terraform_version }} \ | |
| build.pkr.hcl | |