Skip to content

Build And Publish Preview Environment #25423

Build And Publish Preview Environment

Build And Publish Preview Environment #25423

name: Build And Publish Preview Environment
run-name: Build And Publish Preview Environment
on: [push]
permissions: write-all
jobs:
build-and-publish:
runs-on: ubuntu-latest
env:
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0 # max depth
- name: Setup Environment
run: echo "VETS_API_USER_ID=$(id -u)" >> $GITHUB_ENV
- name: Git Version
id: version
uses: codacy/git-version@2.8.0
with:
release-branch: master
- name: Echo the version
run: |
echo ${{ steps.version.outputs.version }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-region: us-gov-west-1
role-to-assume: arn:aws-us-gov:iam::008577686731:role/prt-gha-oidc-role
- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2.0.1
with:
mask-password: true
- name: Build vets-api Docker Image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
build-args: |
BUNDLE_ENTERPRISE__CONTRIBSYS__COM=${{ env.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
USER_ID=${{ env.VETS_API_USER_ID }}
RAILS_ENV=production
context: .
file: Dockerfile
push: true
tags: |
${{ steps.ecr-login.outputs.registry }}/dsva/preview-environment/vets-api:${{ steps.version.outputs.version }}
- name: Create git tag if on master
if: github.ref == 'refs/heads/master'
run: |
git tag ${{ steps.version.outputs.version }}
git push origin ${{ steps.version.outputs.version }}
- name: Inject Version into helm chart
working-directory: ./helmCharts/vets-api
run: |
yq e -i '.image.tag = "${{ steps.version.outputs.version }}"' values.yaml
yq e -i '.version = "${{ steps.version.outputs.version }}"' Chart.yaml
- name: helm Package and Publish
working-directory: ./helmCharts
run: |
helm package vets-api
aws ecr get-login-password --region us-gov-west-1 | helm registry login --username AWS --password-stdin 008577686731.dkr.ecr.us-gov-west-1.amazonaws.com
helm push vets-api-${{ steps.version.outputs.version }}.tgz oci://008577686731.dkr.ecr.us-gov-west-1.amazonaws.com/dsva/helm
- name: Add Failure label
uses: actions-ecosystem/action-add-labels@v1
if: ${{ github.event_name == 'pull_request' && failure() && !contains(github.event.pull_request.labels.*.name, 'pe-failure') }}
with:
number: ${{ github.event.pull_request.number }}
labels: |
pe-failure
- name: Remove Failure label
uses: actions-ecosystem/action-remove-labels@v1
if: ${{ github.event_name == 'pull_request' && success() && contains(github.event.pull_request.labels.*.name, 'pe-failure') }}
with:
number: ${{ github.event.pull_request.number }}
labels: |
pe-failure