Skip to content
Open
51 changes: 51 additions & 0 deletions .github/workflows/example-build-docker.yml
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:
- example/pipeline-march # 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: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
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: "697698820969.dkr.ecr.us-east-1.amazonaws.com/web-app"
IMAGE_TAG: latest-march
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!')});
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