Skip to content

Commit

Permalink
ci: add pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellevissa committed Jun 13, 2024
1 parent cf17ef3 commit 903246a
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
78 changes: 78 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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

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@v3n
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 --net host --restart=unless-stopped --name ${{ env.APP_NAME}} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
package-lock.json
package-lock.json
dist
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:22-alpine3.19 AS builder

WORKDIR /opt/app

COPY package*.json .

RUN npm i && npm i -g serve

COPY . .

RUN npm run build

ENTRYPOINT [ "serve", "./dist", "-l", "tcp://0.0.0.0:5173"]

0 comments on commit 903246a

Please sign in to comment.