diff --git a/.github/workflows/actions/lambda/action.yml b/.github/workflows/actions/lambda/action.yml index 7c13391..b3364de 100644 --- a/.github/workflows/actions/lambda/action.yml +++ b/.github/workflows/actions/lambda/action.yml @@ -1,7 +1,40 @@ -name: "Lambda Shared Action" -description: "Common setup for Lambda jobs" +name: "Build and Push Lambda Image to ECR" +description: "Reusable action for building and pushing lambda Docker image to ECR" + +inputs: + lambda_name: + description: "Lambda name / ECR repo name" + required: true + dockerfile_path: + description: "Path to Dockerfile" + required: true + aws_region: + description: "AWS region" + required: false + default: "eu-west-2" + runs: using: "composite" steps: - - run: echo "This is the lambda shared action" - shell: bash \ No newline at end of file + - uses: actions/checkout@v4 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ inputs.aws_region }} + + - name: Log in to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build and push Docker image + shell: bash + run: | + IMAGE_URI=${{ steps.login-ecr.outputs.registry }}/${{ inputs.lambda_name }}:latest + echo "Building Docker image for ${{ inputs.lambda_name }}..." + docker build -t $IMAGE_URI -f ${{ inputs.dockerfile_path }} . + + echo "Pushing to ECR..." + docker push $IMAGE_URI diff --git a/.github/workflows/actions/terraform-deploy/action.yml b/.github/workflows/actions/terraform-deploy/action.yml new file mode 100644 index 0000000..d500fd6 --- /dev/null +++ b/.github/workflows/actions/terraform-deploy/action.yml @@ -0,0 +1,30 @@ +name: "Terraform Plan Shared Config" +description: "Plans shared Terraform config for Lambdas" + +inputs: + working_directory: + description: "Directory containing Terraform config" + required: true + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Terraform Init + working-directory: ${{ inputs.working_directory }} + shell: bash + run: terraform init -reconfigure + + - name: Terraform Plan + working-directory: ${{ inputs.working_directory }} + shell: bash + run: terraform plan -out=tfplan + + - name: Terraform Apply + working-directory: ${{ inputs.working_directory }} + shell: bash + run: terraform apply -auto-approve tfplan diff --git a/.github/workflows/lambda_main.yml b/.github/workflows/lambda_main.yml index e9fc185..02fa1c6 100644 --- a/.github/workflows/lambda_main.yml +++ b/.github/workflows/lambda_main.yml @@ -1,91 +1,35 @@ -name: Script to deploy lambdas to aws +name: Lambda Main Workflow on: push: - branches: [feature/seperate_terraform_with_different_states, main] + branches: [main, feature/seperate_terraform_with_different_states] env: AWS_REGION: eu-west-2 jobs: - build-and-push-to-ecr-for-lambda-example: + lambda-ecr-example: runs-on: ubuntu-latest - env: - ECR_REPOSITORY: lambda_example - permissions: id-token: write contents: read steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Run lambda shared action - uses: ./.github/workflows/actions/lambda + - name: Build and deploy Lambda example + uses: ./.github/actions/lambda-deploy + with: + lambda_name: lambda_example + dockerfile_path: deployment/lambda/lambda_example/docker/Dockerfile - # - name: AWS credentials - # uses: aws-actions/configure-aws-credentials@v4 - # with: - # # as of 14/07/2025 it'll be using user:Junte's keys - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # aws-region: ${{ secrets.AWS_REGION }} + extractor-and-loader: + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read - # - name: Log in to Amazon ECR - # id: login-ecr - # uses: aws-actions/amazon-ecr-login@v2 - - # - name: Build, tag, and push Docker image to ECR - # env: - # ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - # IMAGE_TAG: latest - # run: | - # IMAGE_URI=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} - # echo "pwd" - # pwd - # ls -la - # echo "Building Docker image..." - # docker build -t $IMAGE_URI -f deployment/lambda/lambda_example/docker/Dockerfile . - - # echo "Pushing Docker image to ECR..." - # docker push $IMAGE_URI - - # build-and-push-to-ecr-for-extractor-and-loader-example: - # runs-on: ubuntu-latest - # env: - # ECR_REPOSITORY: extractor_and_loader - - # permissions: - # id-token: write - # contents: read - - # steps: - # - name: Checkout code - # uses: actions/checkout@v4 - - # - name: AWS credentials - # uses: aws-actions/configure-aws-credentials@v4 - # with: - # # as of 14/07/2025 it'll be using user:Junte's keys - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # aws-region: ${{ secrets.AWS_REGION }} - - # - name: Log in to Amazon ECR - # id: login-ecr - # uses: aws-actions/amazon-ecr-login@v2 - - # - name: Build, tag, and push Docker image to ECR - # env: - # ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - # IMAGE_TAG: latest - # run: | - # IMAGE_URI=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} - # echo "pwd" - # pwd - # ls -la - # echo "Building Docker image..." - # docker build -t $IMAGE_URI -f deployment/lambda/extractor_and_loader/docker/Dockerfile . - - # echo "Pushing Docker image to ECR..." - # docker push $IMAGE_URI \ No newline at end of file + steps: + - name: Build and deploy Extractor & Loader Lambda + uses: ./.github/actions/lambda-deploy + with: + lambda_name: extractor_and_loader + dockerfile_path: deployment/lambda/extractor_and_loader/docker/Dockerfile