Skip to content

Commit

Permalink
Merge pull request #89 from Opetushallitus/OK-613__lampi-siirto
Browse files Browse the repository at this point in the history
Ok 613  lampi siirto
  • Loading branch information
augustk authored Jan 10, 2025
2 parents 4c9103d + 14ada2c commit 9b1fc17
Show file tree
Hide file tree
Showing 19 changed files with 3,545 additions and 37 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build-lampi-siirtaja.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build Lampi-siirtäjä Container

on:
workflow_dispatch:
push:
paths:
- '.github/workflows/build-lampi-siirtaja.yml'
- 'lampi-siirtaja-container/**'

permissions:
id-token: write
contents: read

jobs:
build-and-deploy-container:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.AWS_OVARA_UTILITY_ROLE_ARN }}
role-session-name: ovara-lampi-siirtaja-ecr-push
aws-region: eu-west-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ovara-lampi-siirtaja
IMAGE_TAG: ga-${{ github.run_number }}
run: |
cd lampi-siirtaja-container
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
6 changes: 3 additions & 3 deletions cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import { S3Stack } from '../lib/s3-stack';
const app = new cdk.App();
const environmentName = app.node.tryGetContext('environment') || process.env.ENVIRONMENT;
const ecsImageTag = app.node.tryGetContext('ecsImageTag');
const props = getGenericStackProps(environmentName);
const accountId = process.env.CDK_DEFAULT_ACCOUNT || '';
const props = getGenericStackProps(environmentName, accountId);
const config = props.config;

const accountId = process.env.CDK_DEFAULT_ACCOUNT;

const externalRolesStack = new ExternalRolesStack(
app,
`${config.environment}-ExternalRolesStack`,
Expand Down Expand Up @@ -71,6 +70,7 @@ const databaseStack = new DatabaseStack(app, `${config.environment}-DatabaseStac
});

const ecsStack = new EcsStack(app, `${config.environment}-EcsStack`, {
auroraCluster: databaseStack.auroraCluster,
auroraSecurityGroup: databaseStack.auroraSecurityGroup,
githubActionsDeploymentRole: externalRolesStack.githubActionsDeploymentRole,
ecsImageTag: ecsImageTag,
Expand Down
6 changes: 6 additions & 0 deletions cdk/config/testi.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@
"minute": "30",
"hour": "5-15/1",
"weekDay": "2-6/1"
},
"lampiSiirtajaEnabled": "true",
"lampiSiirtajaCron": {
"minute": "0",
"hour": "0",
"weekDay": "2-6/1"
}
}
6 changes: 6 additions & 0 deletions cdk/config/tuotanto.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@
"minute": "30",
"hour": "5-15/2",
"weekDay": "2-6/1"
},
"lampiSiirtajaEnabled": "false",
"lampiSiirtajaCron": {
"minute": "0",
"hour": "0",
"weekDay": "2-6/1"
}
}
6 changes: 5 additions & 1 deletion cdk/files/bastion/ensure-psql-roles-up-to-date.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ echo ""
echo "Role 'oph_group' is not needed anymore, drop it."
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "drop role oph_group;"
echo ""
echo "Creating user insert_raw_user nad role insert_raw_role (for IAM authentication"
echo "Creating user insert_raw_user nad role insert_raw_role (for IAM authentication)"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "create schema raw;"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "create role insert_raw_role;"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "grant usage on schema raw to insert_raw_role;"
Expand All @@ -69,5 +69,9 @@ PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "grant ins
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "create user insert_raw_user;"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "grant rds_iam to insert_raw_user;"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "grant insert_raw_role to insert_raw_user;"
echo "Creating AWS S3 extension"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "create extension aws_s3 cascade;"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "grant usage on schema aws_s3 to app;"
PGPASSWORD=$master_pw psql -h $host --user oph --dbname $db --command "grant execute on all functions in schema aws_s3 to app;"
echo ""
echo "DONE!"
9 changes: 8 additions & 1 deletion cdk/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as cdk from 'aws-cdk-lib';
import * as appscaling from 'aws-cdk-lib/aws-applicationautoscaling';

export interface GenericStackProps extends cdk.StackProps {
accountId: string;
config: Config;
}

Expand All @@ -23,6 +24,8 @@ export interface Config {
lampiFileHandlerActive: string;
dbtProcessingEnabled: string;
dbtCron: appscaling.CronOptions;
lampiSiirtajaEnabled: string;
lampiSiirtajaCron: appscaling.CronOptions;
profile: string;
publicHostedZone: string;
siirtotiedostot: {
Expand All @@ -35,11 +38,15 @@ export interface Config {
};
}

export const getGenericStackProps = (environment: string): GenericStackProps => {
export const getGenericStackProps = (
environment: string,
accountId: string
): GenericStackProps => {
const filename: string = `config/${environment}.json`;
const fileContent: string = fs.readFileSync(filename, 'utf8');
const config: Config = JSON.parse(fileContent);
return {
accountId: accountId,
config: config,
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
Expand Down
2 changes: 2 additions & 0 deletions cdk/lib/database-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface DatabaseStackProps extends GenericStackProps {
export class DatabaseStack extends cdk.Stack {
public readonly auroraSecurityGroup: ec2.ISecurityGroup;
public readonly lampiTiedostoKasiteltyTable: dynamodb.ITableV2;
public readonly auroraCluster: rds.IDatabaseCluster;

constructor(scope: Construct, id: string, props: DatabaseStackProps) {
super(scope, id, props);
Expand Down Expand Up @@ -123,6 +124,7 @@ export class DatabaseStack extends cdk.Stack {
: rds.DBClusterStorageType.AURORA,
}
);
this.auroraCluster = auroraCluster;

new cdk.CfnOutput(this, 'AuroraClusterResourceId', {
exportName: `${config.environment}-opiskelijavalinnanraportointi-aurora-cluster-resourceid`,
Expand Down
Loading

0 comments on commit 9b1fc17

Please sign in to comment.