Skip to content

ci: bind container port #3

ci: bind container port

ci: bind container port #3

Workflow file for this run

name: Pipeline CI
on:
push:
branches:
- main
- develop
- feat/deploy
permissions: write-all
env:
REGISTRY: ghcr.io
IMAGE_NAME: rafaellevissa/bank-webapp:latest
APP_NAME: react-relay-graphql
APP_PORT: 5173
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Installing Dependencies
run: npm install
- name: Create dotenv
run: echo "${{ secrets.ENV }}" | base64 --decode > .env
- run: npm run test
build:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Github Registrey
if: success()
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create dotenv
run: echo "${{ secrets.ENV }}" | base64 --decode > .env
- name: Build image api
run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} .
- name: Publish image api
run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: EC2 Deployment
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |-
docker container stop ${{ env.APP_NAME}} || true
docker container rm ${{ env.APP_NAME}} || true
docker login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
docker run -d -p ${{ env.APP_PORT }}:${{ env.APP_PORT }} --restart=unless-stopped --name ${{ env.APP_NAME}} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}