From f5dfe7ad0e7eb99488ce5cd3e98f473bec14c61a Mon Sep 17 00:00:00 2001 From: XHunter Date: Wed, 20 Dec 2023 12:47:57 +0530 Subject: [PATCH] migrate(ci/cd): migrate builder from contabo to linode --- .github/workflows/main.yml | 71 +++++++++++--------------------------- 1 file changed, 20 insertions(+), 51 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1d28ae2..c93836f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,61 +1,30 @@ -# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - name: Build on: push: - branches: [ "main" ] + branches: ["main"] jobs: Deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Use Node.js 16.13.2 - uses: actions/setup-node@v3 - with: - node-version: 16.13.2 - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v2 - with: - context: ./ - file: ./Dockerfile - push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio:latest - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} - - - name: Cleaning remote docker image and container - uses: fifsky/ssh-action@master - continue-on-error: true - with: - command: | - docker rm $(docker stop $(docker ps -a -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio --format="{{.ID}}")) && - docker rmi ${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio - host: ${{ secrets.HOST }} - user: ${{ secrets.USERNAME }} - pass: ${{ secrets.PASSWORD}} - port: ${{ secrets.PORT}} + - uses: actions/checkout@v3 + - name: Use Node.js 16.13.2 + uses: actions/setup-node@v3 + with: + node-version: 16.13.2 - - name: Building and deploying new website - uses: fifsky/ssh-action@master - with: - command: | - docker run -d -p 8080:80 --name koders-portfolio ${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio - host: ${{ secrets.HOST }} - user: ${{ secrets.USERNAME }} - pass: ${{ secrets.PASSWORD}} - port: ${{ secrets.PORT}} + - name: Cleaning remote docker image and container + uses: fifsky/ssh-action@master + continue-on-error: true + with: + command: | + cd /root/portfolio/ + git pull + docker build . -t koders-portfolio + docker rm $(docker stop $(docker ps -a -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio --format="{{.ID}}")) && + docker rmi koders-portfolio + docker run -d -p 8080:80 --name koders-portfolio ${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio + host: ${{ secrets.REMOTE_HOST }} + user: ${{ secrets.REMOTE_USER }} + pass: ${{ secrets.REMOTE_PASSWORD}}