From f8381dd4fd535b958f4dbae5bbedbe6d47d737b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique?= Date: Wed, 22 Jan 2025 21:38:36 -0300 Subject: [PATCH] adding pipeline and dockerfile --- .gitea/workflows/ci.yml | 18 ++++++++++++ .gitea/workflows/master.yml | 58 +++++++++++++++++++++++++++++++++++++ Dockerfile | 20 +++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100644 .gitea/workflows/master.yml create mode 100644 Dockerfile diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..f9f5938 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,18 @@ +name: CI + +on: + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup project + run: npm install + - name: Build + run: npm run build + diff --git a/.gitea/workflows/master.yml b/.gitea/workflows/master.yml new file mode 100644 index 0000000..4e8968a --- /dev/null +++ b/.gitea/workflows/master.yml @@ -0,0 +1,58 @@ +name: Master Build + +on: + push: + branches: [ "master" ] + +jobs: + build_amd64: + name: Build and Push Docker Image (amd64) + runs-on: self-hosted-ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install docker and docker compose + run: | + apt update + apt install -y docker + + - name: Login to Docker Hub + uses: https://github.com/docker/login-action@v3.3.0 + with: + registry: git.ivanch.me + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_ACCESS_TOKEN }} + + - name: Build Docker image and push + id: docker_build + uses: https://github.com/docker/build-push-action@v6.12.0 + with: + context: ./ + file: ./Dockerfile + push: true + tags: https://git.ivanch.me/ivanch/new-home/home-page:latest + platforms: linux/amd64 + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + deploy: + name: Update running container + runs-on: self-hosted-ubuntu-latest + needs: build_amd64 + + steps: + - name: Recreate container + uses: https://github.com/appleboy/ssh-action@v1.2.0 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + script: | + cd ${{ secrets.PROJECT_DIR }} + docker compose down + docker compose rm + docker compose pull + docker compose up -d diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c82682e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM node:14 AS build + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN npm run build + +FROM nginx:alpine + +COPY --from=build /app/build /usr/share/nginx/html + +EXPOSE 80 + +# Start Nginx server +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file