diff --git a/.github/workflows/aws.yml b/.github/workflows/aws.yml new file mode 100644 index 0000000..97e0e9b --- /dev/null +++ b/.github/workflows/aws.yml @@ -0,0 +1,79 @@ +# This workflow will build and push a new container image to Amazon ECR, +# and then will deploy a new task definition to Amazon ECS, when there is a push to the "main" branch. +# +# To use this workflow, you will need to complete the following set-up steps: +# +# 1. Create an ECR repository to store your images. +# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. +# Replace the value of the `ECR_REPOSITORY` environment variable in the workflow below with your repository's name. +# Replace the value of the `AWS_REGION` environment variable in the workflow below with your repository's region. +# +# 2. Create an ECS task definition, an ECS cluster, and an ECS service. +# For example, follow the Getting Started guide on the ECS console: +# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun +# Replace the value of the `ECS_SERVICE` environment variable in the workflow below with the name you set for the Amazon ECS service. +# Replace the value of the `ECS_CLUSTER` environment variable in the workflow below with the name you set for the cluster. +# +# 3. Store your ECS task definition as a JSON file in your repository. +# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. +# Replace the value of the `ECS_TASK_DEFINITION` environment variable in the workflow below with the path to the JSON file. +# Replace the value of the `CONTAINER_NAME` environment variable in the workflow below with the name of the container +# in the `containerDefinitions` section of the task definition. +# +# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. +# See the documentation for each action used below for the recommended IAM policies for this IAM user, +# and best practices on handling the access key credentials. + +name: Deploy to Amazon ECS + +on: + push: + tags: + - '*' + +env: + AWS_REGION: eu-north-1 # set this to your preferred AWS region, e.g. us-west-1 + ECR_REPOSITORY: 337878073417.dkr.ecr.eu-north-1.amazonaws.com/test # set this to your Amazon ECR repository name + ECS_SERVICE: test # set this to your Amazon ECS service name + ECS_CLUSTER: citibeats-sandbox # set this to your Amazon ECS cluster name + +permissions: + contents: read + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + 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@v1 + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + IMAGE_TAG: "latest" + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker build -t $ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REPOSITORY:$IMAGE_TAG + echo "image=$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + + - name: Deploy again - substitute currently running tasks with tasks with the actual latest image. + id: force-deployment + run: | + aws ecs update-service --cluster ${{ env.ECS_CLUSTER }} --service ${{ env.ECS_SERVICE }} --force-new-deployment diff --git a/CHANGELOG.yml b/CHANGELOG.yml deleted file mode 100644 index 77ff0e6..0000000 --- a/CHANGELOG.yml +++ /dev/null @@ -1,22 +0,0 @@ -v0.3.2: - date: "2017-12-07" - changes: - - "Make port 3000 the default everywhere" - - "Add a Makefile" -v0.3.1: - date: "2017-09-18" - changes: - - "Enable basic multi-stage build + adapt CircleCi scripts" - - "Use read-pkg-up instead of pkg-up" -v0.3.0: - date: "2017-09-17" - changes: - - "Add endpoint cmd-cron" -v0.2.0: - date: "2017-09-17" - changes: - - "Add endpoint cmd" -v0.1.0: - date: "2017-09-16" - changes: - - "Initial commit" diff --git a/Dockerfile b/Dockerfile index 2363953..227c98d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ ARG NODE_VER="14.3.0" # -------------------------------------- # BASE NODE # -------------------------------------- -FROM node:${NODE_VER}-alpine as BASE +FROM node:${NODE_VER}-alpine as base ARG PORT=3000 ENV PORT=$PORT @@ -16,7 +16,7 @@ COPY package.json package-lock.json ./ # -------------------------------------- # DEPENDENCIES # -------------------------------------- -FROM BASE as DEPENDENCIES +FROM base as dependencies RUN npm install --only=production @@ -31,7 +31,7 @@ RUN npm install # TEST # -------------------------------------- # run linters, setup and tests -FROM dependencies AS TEST +FROM dependencies AS test COPY .eslintrc.json . COPY /src ./src/ @@ -42,7 +42,7 @@ RUN npm run lint && npm run test # -------------------------------------- # RELEASE # -------------------------------------- -FROM BASE as RELEASE +FROM base as release # copy production node_modules COPY --from=dependencies /app/prod_node_modules ./node_modules diff --git a/Makefile b/Makefile index a18fcfa..a38a259 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ help: ## Show this help. @echo '' .PHONY: help -gen-readme: ## Generate README.md (using docker-verb) +gen-readme: ## Generate READMfE.md (using docker-verb) docker run --rm -v ${PWD}:/opt/verb stefanwalther/verb .PHONY: gen-readme diff --git a/README.md b/README.md index 9174309..5f5db3a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # docker-test -> Sample docker image to test various scenarios with Docker. +> Sample docker image to test various scenarios with Docker [](https://circleci.com/gh/stefanwalther/docker-test/tree/master) [](https://github.com/sindresorhus/eslint-config-xo-space) @@ -129,7 +129,7 @@ Pull requests and stars are always welcome. For bugs and feature requests, [plea 2. Work on whatever bug or feature you wish 3. Create a pull request (PR) -I cannot guarantee that I will merge all PRs but I will evaluate them all. +I cannot guarantee that I will merge all PRs but I will evaluate them all ### License Copyright © 2020, [Stefan Walther](http://qliksite.io). diff --git a/a b/a new file mode 100644 index 0000000..e69de29 diff --git a/b b/b new file mode 100644 index 0000000..e69de29 diff --git a/c b/c new file mode 100644 index 0000000..e69de29 diff --git a/d b/d new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/default/default.controller.js b/src/modules/default/default.controller.js index d6a7c76..4874a3f 100644 --- a/src/modules/default/default.controller.js +++ b/src/modules/default/default.controller.js @@ -3,10 +3,10 @@ class Controller { static get(req, res) { console.log('We are here'); if (req.query.output === 'text') { - res.send('Hello World').end(); + res.sendFile(path.join('/.index.html')); } else { - res.json({text: 'Hello World'}).end(); + res.sendFile(path.join('./index.html')); } } } diff --git a/src/modules/default/index.html b/src/modules/default/index.html new file mode 100644 index 0000000..4dfdc18 --- /dev/null +++ b/src/modules/default/index.html @@ -0,0 +1,15 @@ + + +
+This is some underlying text.
+ + \ No newline at end of file