Add environment input to e2e-test workflow #1
Workflow file for this run
This file contains 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
name: deploy | |
on: | |
workflow_call: | |
inputs: | |
environment: | |
required: true | |
type: choice | |
options: | |
- dev | |
- test | |
inputs: | |
module: | |
required: true | |
type: choice | |
options: | |
- api | |
- worker | |
workflow_dispatch: | |
inputs: | |
environment: | |
required: true | |
type: choice | |
options: | |
- dev | |
- test | |
inputs: | |
module: | |
required: true | |
type: choice | |
options: | |
- api | |
- worker | |
jobs: | |
deploy: | |
runs-on: self-hosted | |
env: | |
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true | |
AWS_REGION: ${{ vars.AWS_REGION }} | |
DEPLOYMENT_ENV: ${{ vars[format('{0}_DEPLOYMENT_ENV', inputs.environment)] }} | |
defaults: | |
run: | |
working-directory: ./${{ inputs.module }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Install Maven 3.6.3 | |
run: | | |
export PATH="$PATH:/opt/maven/bin" | |
echo "PATH=$PATH" >> $GITHUB_ENV | |
if mvn -v; then echo "Maven already installed" && exit 0; else echo "Installing Maven"; fi | |
tmpdir="$(mktemp -d)" | |
curl -LsS https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | tar xzf - -C "$tmpdir" | |
sudo rm -rf /opt/maven | |
sudo mv "$tmpdir/apache-maven-3.6.3" /opt/maven | |
- name: Set env vars from AWS params in BCDA management account | |
uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main | |
with: | |
params: | | |
ARTIFACTORY_URL=/artifactory/url | |
ARTIFACTORY_USER=/artifactory/user | |
ARTIFACTORY_PASSWORD=/artifactory/password | |
- name: Build package | |
run: mvn -U clean package -s settings.xml -DskipTests -Dusername="${ARTIFACTORY_USER}" -Dpassword="${ARTIFACTORY_PASSWORD}" -Drepository_url="${ARTIFACTORY_URL}" | |
- name: Assume role in AB2D Management account | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-region: ${{ vars.AWS_REGION }} | |
role-to-assume: arn:aws:iam::${{ secrets.MGMT_ACCOUNT_ID }}:role/delegatedadmin/developer/ab2d-mgmt-github-actions | |
- name: Push to ECR | |
run: | | |
ECR_REPO_DOMAIN="${{ secrets.MGMT_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com" | |
aws ecr get-login-password | docker login --username AWS --password-stdin "$ECR_REPO_DOMAIN" | |
ECR_REPO_URI="$ECR_REPO_DOMAIN/ab2d_${{ inputs.module }}" | |
SHA_SHORT=$(git rev-parse --short HEAD) | |
echo "Building image for commit sha $SHA_SHORT" | |
docker build \ | |
-t "${ECR_REPO_URI}:${DEPLOYMENT_ENV}-$SHA_SHORT" \ | |
-t "${ECR_REPO_URI}:${DEPLOYMENT_ENV}-latest" . | |
echo "Pushing image" | |
docker push "${ECR_REPO_URI}" --all-tags | |
- name: Assume role in AB2D impl account | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-region: ${{ vars.AWS_REGION }} | |
role-to-assume: arn:aws:iam::${{ secrets[format('{0}_ACCOUNT_ID', inputs.environment)] }}:role/delegatedadmin/developer/ab2d-${{ inputs.environment }}-github-actions | |
- name: Deploy latest images in ECR to ECS | |
run: aws ecs update-service --cluster ${DEPLOYMENT_ENV}-${{ inputs.module }} --service ${DEPLOYMENT_ENV}-${{ inputs.module }} --force-new-deployment |