diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 87a14c3..59af93d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,103 +9,115 @@ on: jobs: deploy: runs-on: self-hosted + steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: Semantic Release - uses: cycjimmy/semantic-release-action@v2 - id: semantic - with: - semantic_version: 16 - extra_plugins: | - @saithodev/semantic-release-backmerge - conventional-changelog-eslint - branches: | - [ - 'main', - { - name: 'alpha', - prerelease: true - }, - { - name: 'beta', - prerelease: true - } - ] - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Because Semantic Realese deleted the .npmrc file, it was necessary to insert two steps to backup the file. + - name: BKP .npmrc Step 1 + run: | + cp .npmrc .npmrcbkp + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v2 + id: semantic + with: + semantic_version: 16 + extra_plugins: | + @saithodev/semantic-release-backmerge + conventional-changelog-eslint + branches: | + [ + 'main', + { + name: 'alpha', + prerelease: true + }, + { + name: 'beta', + prerelease: true + } + ] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Update Pip - if: steps.semantic.outputs.new_release_published == 'true' - run: | - python3 -m pip install --upgrade pip + # Because Semantic Realese deleted the .npmrc file, it was necessary to insert two steps to backup the file. + - name: BKP .npmrc Step 2 + run: | + cp .npmrcbkp .npmrc + - name: Update Pip + if: steps.semantic.outputs.new_release_published == 'true' + run: | + python3 -m pip install --upgrade pip + ls -a + - name: Install Docker Compose + if: steps.semantic.outputs.new_release_published == 'true' + run: | + python3 -m pip install docker-compose --upgrade + ls -a + - name: Install AWS CLI + if: steps.semantic.outputs.new_release_published == 'true' + run: | + python3 -m pip install awscli --upgrade + ls -a + - name: Install AWS Elastic Beanstalk CLI + if: steps.semantic.outputs.new_release_published == 'true' + run: | + python3 -m pip install awsebcli --upgrade + ls -a + - name: Configure AWS Region + if: steps.semantic.outputs.new_release_published == 'true' + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-east-1 - - name: Install Docker Compose - if: steps.semantic.outputs.new_release_published == 'true' - run: | - python3 -m pip install docker-compose --upgrade + - name: Extract Environment + if: steps.semantic.outputs.new_release_published == 'true' + shell: bash + run: | + ls -a + if [ ${GITHUB_REF} == "refs/heads/main" ]; then + echo "##[set-output name=result;]$(echo "production")" + else + echo "##[set-output name=result;]$(echo ${GITHUB_REF#refs/heads/})" + fi + id: extract_environment - - name: Install AWS CLI - if: steps.semantic.outputs.new_release_published == 'true' - run: | - python3 -m pip install awscli --upgrade + - name: Login to AWS ECR + if: steps.semantic.outputs.new_release_published == 'true' + id: login_ecr + uses: aws-actions/amazon-ecr-login@v1 - - name: Install AWS Elastic Beanstalk CLI - if: steps.semantic.outputs.new_release_published == 'true' - run: | - python3 -m pip install awsebcli --upgrade - - - name: Configure AWS Region - if: steps.semantic.outputs.new_release_published == 'true' - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-region: us-east-1 - - - name: Extract Environment - if: steps.semantic.outputs.new_release_published == 'true' - shell: bash - run: | - if [ ${GITHUB_REF} == "refs/heads/main" ]; then - echo "##[set-output name=result;]$(echo "production")" - else - echo "##[set-output name=result;]$(echo ${GITHUB_REF#refs/heads/})" - fi - id: extract_environment - - - name: Login to AWS ECR - if: steps.semantic.outputs.new_release_published == 'true' - id: login_ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Build, Tag, and Push Image to AWS ECR - if: steps.semantic.outputs.new_release_published == 'true' - env: - ENV: ${{ steps.extract_environment.outputs.result }} - IMAGE_TAG: ${{ steps.semantic.outputs.new_release_version }} - run: | - docker-compose -f build.docker-compose.yml build - docker-compose -f build.docker-compose.yml push - - - name: Create ZIP file to Deploy AWS Beanstalk - if: steps.semantic.outputs.new_release_published == 'true' - env: - ENV: ${{ steps.extract_environment.outputs.result }} - IMAGE_TAG: ${{ steps.semantic.outputs.new_release_version }} - run: | - sed -i -e "s/\${ENV}/$ENV/g" docker-compose.yml - sed -i -e "s/\${IMAGE_TAG}/$IMAGE_TAG/g" docker-compose.yml - zip deploy.zip docker-compose.yml - - - name: Deploy AWS Beanstalk - if: steps.semantic.outputs.new_release_published == 'true' - env: - ENV: ${{ steps.extract_environment.outputs.result }} - AWS_REGION: us-east-1 - APP_NAME: maestro - run: | - [[ -d .elasticbeanstalk/ ]] && rm -R .elasticbeanstalk/ - printf "1\nn" | eb init $APP_NAME --region $AWS_REGION - eb use $APP_NAME-$ENV - echo -e "deploy:\n artifact: deploy.zip" >> .elasticbeanstalk/config.yml - eb deploy + - name: Build, Tag, and Push Image to AWS ECR + if: steps.semantic.outputs.new_release_published == 'true' + env: + ENV: ${{ steps.extract_environment.outputs.result }} + IMAGE_TAG: ${{ steps.semantic.outputs.new_release_version }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + docker-compose -f build.docker-compose.yml build --build-arg NPM_TOKEN=${NPM_TOKEN} + docker-compose -f build.docker-compose.yml push + ls -a + - name: Create ZIP file to Deploy AWS Beanstalk + if: steps.semantic.outputs.new_release_published == 'true' + env: + ENV: ${{ steps.extract_environment.outputs.result }} + IMAGE_TAG: ${{ steps.semantic.outputs.new_release_version }} + run: | + sed -i -e "s/\${ENV}/$ENV/g" docker-compose.yml + sed -i -e "s/\${IMAGE_TAG}/$IMAGE_TAG/g" docker-compose.yml + zip deploy.zip docker-compose.yml + ls -a + - name: Deploy AWS Beanstalk + if: steps.semantic.outputs.new_release_published == 'true' + env: + ENV: ${{ steps.extract_environment.outputs.result }} + AWS_REGION: us-east-1 + APP_NAME: maestro + run: | + [[ -d .elasticbeanstalk/ ]] && rm -R .elasticbeanstalk/ + printf "1\nn" | eb init $APP_NAME --region $AWS_REGION + eb use $APP_NAME-$ENV + echo -e "deploy:\n artifact: deploy.zip" >> .elasticbeanstalk/config.yml + eb deploy \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc65444..1ec0dd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,19 +16,21 @@ jobs: - name: Install Docker Compose run: | python3 -m pip install docker-compose --upgrade - - name: Build env: ENV: test IMAGE_TAG: test + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | export ENV=test - docker-compose -f build.docker-compose.yml build - + export IMAGE_TAG=test + docker-compose -f build.docker-compose.yml build --build-arg NPM_TOKEN=${NPM_TOKEN} - name: Run Test env: ENV: test IMAGE_TAG: test + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | export ENV=test - docker-compose run --rm --entrypoint="npm run test" maestro + export IMAGE_TAG=test + docker-compose -f build.docker-compose.yml run -e NPM_TOKEN=${NPM_TOKEN} --rm --entrypoint="npm run test" maestro \ No newline at end of file diff --git a/.releaserc.json b/.releaserc.json index 1fda875..80c93d6 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -29,7 +29,10 @@ [ "@saithodev/semantic-release-backmerge", { - "branches": ["alpha", "beta"], + "branches": [ + { "from": "main", "to": "alpha" }, + { "from": "main", "to": "beta" } + ], "backmergeStrategy": "merge" } ], diff --git a/Dockerfile b/Dockerfile index 3b435f3..f80c060 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,16 @@ -FROM node:14 as packages +FROM node:14.15.4-alpine3.12 as packages WORKDIR /packages +ARG NPM_TOKEN COPY package.json . +COPY .npmrc . RUN npm install +RUN rm -f ./.npmrc -FROM node:alpine +FROM node:14.15.4-alpine3.12 WORKDIR /app COPY . /app/ +ARG NPM_TOKEN COPY --from=packages /packages/node_modules /app/node_modules RUN npm run build EXPOSE 3333 -ENTRYPOINT npm run start +ENTRYPOINT npm run start \ No newline at end of file