Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/example-build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Push Docker Image to ECR

on:
push:
branches:
- example/pipeline # or specify any branch you want to trigger this workflow on

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2


- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::697698820969:role/GithubActionAssumeRole
aws-region: us-east-1

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

- name: Build, tag, and push Docker image
env:
ECR_URI: "778529894665.dkr.ecr.us-east-1.amazonaws.com/web-app"
IMAGE_TAG: latest
run: |
yarn --frozen-lockfile
yarn nx build api-flowaccount-workshop
docker build -t $ECR_URI:$IMAGE_TAG .
docker push $ECR_URI:$IMAGE_TAG

# - name: Image digest
# run: |
# IMAGE_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ env.REPO_URI }}:${{ github.sha }})
# echo "Docker image pushed: $IMAGE_DIGEST"
3 changes: 2 additions & 1 deletion apps/api/flowaccount-workshop/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"outputPath": "dist/apps/api/flowaccount-workshop",
"main": "apps/api/flowaccount-workshop/src/main.ts",
"tsConfig": "apps/api/flowaccount-workshop/tsconfig.app.json",
"webpackConfig": "apps/api/flowaccount-workshop/webpack.config.ts",
"assets": [
"apps/api/flowaccount-workshop/src/assets",
"apps/api/flowaccount-workshop/src/README.md"
Expand All @@ -19,7 +20,7 @@
"configurations": {}
},
"serve": {
"executor": "@nx/node:node",
"executor": "@nx/js:node",
"options": {
"buildTarget": "api-flowaccount-workshop:build"
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/flowaccount-workshop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ app.use(function (err, req, res, next) {
res.render('error');
});

app.listen(process.env.SERVER_PORT || 3000, () => { console.log('listening!')});
app.listen(process.env.SERVER_PORT || 8081, () => { console.log('listening!')});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build and Push Docker Image to ECR

on:
push:
branches:
- main # or specify any branch you want to trigger this workflow on

permissions:
id-token: write
contents: read

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::697698820969:role/GithubActionAssumeRole
aws-region: us-east-1

- name: Get ECR repository URI
id: ecr_uri
run: echo "REPO_URI=$(aws ecr describe-repositories --repository-names my-repo --query 'repositories[0].repositoryUri' --output text)" >> $GITHUB_ENV

- name: Build, tag, and push Docker image
env:
ECR_URI: "697698820969.dkr.ecr.us-east-1.amazonaws.com/web-app"
IMAGE_TAG: latest-ball
run: |
docker build -t $ECR_URI:$IMAGE_TAG .
docker push $ECR_URI:$IMAGE_TAG

- name: Image digest
run: |
IMAGE_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ env.REPO_URI }}:${{ github.sha }})
echo "Docker image pushed: $IMAGE_DIGEST"
42 changes: 42 additions & 0 deletions apps/api/flowaccount-workshop/src/workshops/exmaple-task-def.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"requiresCompatibilities": [
"FARGATE"
],
"containerDefinitions": [
{
"name": "app-container",
"image": "697698820969.dkr.ecr.us-east-1.amazonaws.com/web-app:latest",
"cpu": 512,
"memoryReservation": 512,
"portMappings": [
{
"containerPort": 3000,
"hostPort": 3000,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"secrets": [

],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/web-app",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
}
}
}
],
"family": "web-app-task-def",
"taskRoleArn": "arn:aws:iam::490425202190:role/ECSTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::490425202190:role/ECSTaskExecutionRole",
"networkMode": "awsvpc",
"volumes": [],
"placementConstraints": [],
"tags": []
}
42 changes: 42 additions & 0 deletions apps/api/flowaccount-workshop/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { NxWebpackPlugin } = require('@nx/webpack');
const nodeExternals = require('webpack-node-externals');
const { withExternals } = require('./with-externals');
const { composePlugins } = require('@nx/webpack');

module.exports = composePlugins(
(config, { options, context }) => {
return {
target: 'node',
node: {
__dirname: true
},
module: {
rules: [
{
test: /\.(json)$/,
type: 'src/config',
}
],
},
output: {
globalObject: 'this',
},
plugins: [
new NxWebpackPlugin({
tsConfig: options.tsConfig,
compiler: 'swc',
main: options.main,
outputHashing: false,
ssr: true,
sourceMap: true,
generatePackageJson: options.generatePackageJson,
assets: options.assets,
outputPath: options.outputPath
}),
],

externals: [withExternals([/^aws-cdk-lib\//,/aws-cdk-stack\//,/^aws-cdk-core\//,/^nx-aws-cdk\//]),]
}
});


29 changes: 29 additions & 0 deletions apps/api/flowaccount-workshop/with-externals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NxComposableWebpackPlugin } from '@nx/webpack';
import type { Configuration } from 'webpack';

// @example withExternals([/^@aws-sdk\//, /^@aws-lambda-powertools\//])
export function withExternals(externals: RegExp[]): NxComposableWebpackPlugin {
return function configure(config: Configuration): Configuration {
config.externals = Array.isArray(config.externals)
? config.externals
: config.externals
? [config.externals]
: [];
config.externals.push(function (
ctx,
callback: (
err?: null | Error,
result?: string | boolean | string[] | { [index: string]: any },
) => void,
) {
if (externals.some((e) => e.test(ctx.request))) {
// not bundled
return callback(null, `commonjs ${ctx.request}`);
}
// bundled
callback();
});

return config;
};
}
14 changes: 14 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:fermium

ARG GITCOMMIT=""
ENV GIT_COMMIT_HASH=${GITCOMMIT}

WORKDIR /app

COPY dist/apps/api/flowaccount-workshop/. .

#RUN npm install

CMD ["node", "main.js"]

EXPOSE 8081