diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..99bf151 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,29 @@ +name: Deploy +on: + push: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + name: build docker image + steps: + - name: Git Checkout + 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: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push image to Amazon ECR + run: | + cd demo/lambda/src + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9848d5c..e58e3a0 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,135 @@ terraform.tfstate.d .terraform.lock.hcl terraform.tfstate -terraform.tfstate.backup \ No newline at end of file +terraform.tfstate.backup + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* diff --git a/demo/lambda/deployment/deploy.yaml b/demo/lambda/deployment/deploy.yaml new file mode 100644 index 0000000..bda980f --- /dev/null +++ b/demo/lambda/deployment/deploy.yaml @@ -0,0 +1,3 @@ + + +docker buildx build --platform linux/amd64,linux/arm64 -t 590184123335.dkr.ecr.ap-southeast-1.amazonaws.com/demo-awscd-2024:init . --push \ No newline at end of file diff --git a/demo/lambda/src/Dockerfile b/demo/lambda/src/Dockerfile new file mode 100644 index 0000000..fe2ecca --- /dev/null +++ b/demo/lambda/src/Dockerfile @@ -0,0 +1,7 @@ +FROM public.ecr.aws/lambda/nodejs:14 + +COPY app.js package.json ./ + +RUN npm install + +CMD [ "app.handler" ] \ No newline at end of file diff --git a/demo/lambda/src/app.js b/demo/lambda/src/app.js new file mode 100644 index 0000000..92fdd02 --- /dev/null +++ b/demo/lambda/src/app.js @@ -0,0 +1,7 @@ +exports.handler = async (event) => { + const response = { + statusCode: 200 + body: JSON.stringify('Hello from Lambda!') + }; + return response; +}; diff --git a/demo/lambda/src/package.json b/demo/lambda/src/package.json new file mode 100644 index 0000000..c62b0e7 --- /dev/null +++ b/demo/lambda/src/package.json @@ -0,0 +1,12 @@ +{ + "name": "src", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/iac/ecr.tf b/iac/ecr.tf new file mode 100644 index 0000000..378cd44 --- /dev/null +++ b/iac/ecr.tf @@ -0,0 +1,8 @@ +resource "aws_ecr_repository" "awscd" { + name = "demo-awscd-2024" + image_tag_mutability = "MUTABLE" + + image_scanning_configuration { + scan_on_push = true + } +} \ No newline at end of file