|
| 1 | +name: Create and publish Otp Provider Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'dev' |
| 7 | + |
| 8 | +env: |
| 9 | + IMAGE_NAME: bcgov-sso/otp-provider |
| 10 | + TF_VERSION: 1.2.0 |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-and-push-image: |
| 14 | + permissions: write-all |
| 15 | + runs-on: ubuntu-24.04 |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Set env to development |
| 19 | + if: (github.ref == 'refs/heads/dev' && github.event_name == 'push') |
| 20 | + run: | |
| 21 | + cat >> $GITHUB_ENV <<EOF |
| 22 | + TF_STATE_BUCKET=xgr00q-dev-sso-otp-provider |
| 23 | + TF_STATE_BUCKET_KEY=sso-otp-provider.tfstate |
| 24 | + TF_STATE_DYNAMODB_TABLE=xgr00q-dev-otp-state-locking |
| 25 | + CUSTOM_DOMAIN_NAME=otp-sandbox.loginproxy.gov.bc.ca |
| 26 | + CORS_ORIGINS=https://dev.sandbox.loginproxy.gov.bc.ca,https://test.sandbox.loginproxy.gov.bc.ca,https://sandbox.loginproxy.gov.bc.ca,https://sso-playground.apps.gold.devops.gov.bc.ca |
| 27 | +
|
| 28 | + EOF |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v3 |
| 31 | + |
| 32 | + - uses: hashicorp/setup-terraform@v3 |
| 33 | + |
| 34 | + - name: Configure AWS Credentials |
| 35 | + uses: aws-actions/configure-aws-credentials@v4 |
| 36 | + with: |
| 37 | + role-to-assume: ${{ secrets.DEV_OTP_TF_DEPLOY_ROLE_ARN }} |
| 38 | + aws-region: ca-central-1 |
| 39 | + |
| 40 | + - name: Login to Amazon ECR |
| 41 | + id: login-ecr |
| 42 | + uses: aws-actions/amazon-ecr-login@v2 |
| 43 | + |
| 44 | + - name: Build, tag, and push docker image to Amazon ECR |
| 45 | + env: |
| 46 | + REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 47 | + REPOSITORY: ${{ env.IMAGE_NAME }} |
| 48 | + IMAGE_TAG: latest |
| 49 | + run: | |
| 50 | + echo "Building and pushing Docker image to ECR..." |
| 51 | + docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . |
| 52 | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG |
| 53 | + working-directory: ./docker/otp-provider |
| 54 | + |
| 55 | + - name: Terraform Variables |
| 56 | + run: | |
| 57 | + cat >"config.tf" <<EOF |
| 58 | + terraform { |
| 59 | + backend "s3" { |
| 60 | + bucket = "${{ env.TF_STATE_BUCKET }}" |
| 61 | + key = "${{ env.TF_STATE_BUCKET_KEY }}" |
| 62 | + region = "ca-central-1" |
| 63 | + dynamodb_table = "${{ env.TF_STATE_DYNAMODB_TABLE }}" |
| 64 | + } |
| 65 | + } |
| 66 | + EOF |
| 67 | +
|
| 68 | + cat >"ci.auto.tfvars" <<EOF |
| 69 | + aws_ecr_uri="${{ steps.login-ecr.outputs.registry }}" |
| 70 | + ches_username="${{ secrets.CHES_USERNAME }}" |
| 71 | + ches_password="${{ secrets.CHES_PASSWORD }}" |
| 72 | + custom_domain_name="${{ env.CUSTOM_DOMAIN_NAME }}" |
| 73 | + cors_origins="${{ env.CORS_ORIGINS }}" |
| 74 | + EOF |
| 75 | +
|
| 76 | + working-directory: ./docker/otp-provider/terraform |
| 77 | + |
| 78 | + - name: Terraform Init |
| 79 | + id: init |
| 80 | + run: terraform init -upgrade |
| 81 | + working-directory: ./docker/otp-provider/terraform |
| 82 | + |
| 83 | + - name: Terraform Plan |
| 84 | + id: plan |
| 85 | + run: terraform plan -no-color |
| 86 | + working-directory: ./docker/otp-provider/terraform |
| 87 | + continue-on-error: true |
| 88 | + |
| 89 | + - name: Terraform Plan Status |
| 90 | + if: steps.plan.outcome == 'failure' |
| 91 | + run: exit 1 |
| 92 | + |
| 93 | + - name: Terraform Apply |
| 94 | + if: github.event_name == 'push' |
| 95 | + run: terraform apply -auto-approve |
| 96 | + working-directory: ./docker/otp-provider/terraform |
0 commit comments