Merge pull request #1 from rcmonteiro/feature/configure-release/rcmon… #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
# Grants the workflow permission to create OpenID Connect (OIDC) ID tokens. | |
id-token: write | |
# Grants the workflow read-only access to the repository contents. | |
contents: read | |
jobs: | |
build: | |
name: 'Build and Push' | |
# Definir o runner para rodar as actions | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- uses: pnpm/action-setup@v4 | |
name: Install pnpm | |
with: | |
version: 8 | |
run_install: false | |
- name: Get pnpm store directory | |
shell: bash | |
run: | | |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
- uses: actions/cache@v4 | |
name: Setup pnpm cache | |
with: | |
path: ${{ env.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Install dependencies | |
run: pnpm install | |
- name: Run tests | |
run: pnpm run test | |
- name: Semantic Release | |
uses: cycjimmy/semantic-release-action@v4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
- name: Create tag | |
id: create_tag | |
run: | | |
SHA=$(echo $GITHUB_SHA | head -c7) | |
echo "sha=$SHA" >> $GITHUB_OUTPUT | |
# ------------------------------------------------------------ | |
# Exemplo de publicação no ECR | |
# ------------------------------------------------------------ | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.ECR_ARN }} | |
aws-region: us-east-2 | |
- name: Login to AWS ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and Push Docker image | |
id: build-docker-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
TAG: ${{ steps.create_tag.outputs.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/rcmonteiro_devops_nest_ci:$TAG . | |
docker push $ECR_REGISTRY/rcmonteiro_devops_nest_ci:$TAG | |
docker tag $ECR_REGISTRY/rcmonteiro_devops_nest_ci:$TAG $ECR_REGISTRY/rcmonteiro_devops_nest_ci:latest | |
docker push $ECR_REGISTRY/rcmonteiro_devops_nest_ci:latest | |
IMAGE=$(echo $ECR_REGISTRY/rcmonteiro_devops_nest_ci:$TAG) | |
echo "image=$IMAGE" >> $GITHUB_OUTPUT | |
- name: Deploy to AWS App Runner | |
id: deploy-app-runner | |
uses: awslabs/amazon-app-runner-deploy@main | |
with: | |
service: rcmonteiro_devops_nest_api | |
image: ${{ steps.build-docker-image.outputs.image }} | |
access-role-arn: ${{ secrets.APP_RUNNER_ARN }} | |
region: us-east-2 | |
cpu: 1 | |
memory: 2 | |
port: 3000 | |
wait-for-service-stability-seconds: 180 | |
- name: App Runner Check Status | |
run: | | |
echo "App Runner Status: ${{ steps.deploy-app-runner.outputs.service-url }}" | |
# ------------------------------------------------------------ | |
# Exemplo de publicação no Docker Hub | |
# ------------------------------------------------------------ | |
# - name: Login on Container Registry | |
# uses: docker/login-action@v3 | |
# with: | |
# username: ${{ secrets.DOCKERHUB_USERNAME }} | |
# password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# - name: Build and Push to Docker | |
# uses: docker/build-push-action@v5 | |
# with: | |
# push: true | |
# tags: rcmonteiro/devops-sample-api-ci:${{ steps.create_tag.outputs.sha }},rcmonteiro/devops-sample-api-ci:latest | |
# - name: Build docker image | |
# run: docker build -t rcmonteiro/devops-sample-api-ci:${{ steps.create_tag.outputs.sha }} . | |
# - name: Push image to Docker Hub | |
# run: docker push rcmonteiro/devops-sample-api-ci:${{ steps.create_tag.outputs.sha }} |