Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Using Github Actions

I am using Github as my source control, and using Github Actions as my CI/CD solution. I have a dedicated Windows Server somewhere, which accepts the published version of my repo.

I have a Github Action, which does Built, Test, Publish and Deploy (using FTP). I am not convinced with the "Deploy" idea. for example lets say my website has a huge codebase, and then FTPing everytime when we make a commit (Push) is NOT really a productive idea (i am publishing the published directory...not the Source Code to my server). Sometimes FTPing simply does not work, due to IIS Locking the files. what is the most reliable way to publish/deploy files to a remote server using Github Actions (or any other provider).

below is my sample Yaml file...

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 2.1
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --no-restore --verbosity normal 
    - name: Run the Publish
      run: dotnet publish --configuration Release --no-restore --output ./publish      
      

    - name: FTP-Deploy-Action
      uses: sebastianpopp/ftp-action@releases/v2
      with:
        host: my_host
        user: my_user
        password: ${{ secrets.FTP_PASSWORD }}
        localDir: "/home/runner/work/CiTest/CiTest/CiTest/publish"
        remoteDir: "CI-Test" 
like image 906
user2404597 Avatar asked Sep 17 '25 07:09

user2404597


1 Answers

I wanted to add an answer to this question because Rosco's answer helped me, but I have more to contribute.

We've set up a self-hosted runner on the internal IIS server we want to deploy to. So our GitHub Actions flow looks a bit like yours to begin with (up to the dotnet publish command), but then has some extra bits.

First, still in the cloud, we "upload" artifacts from the build (I'm replacing our project name with "Foo"):

- name: Upload a Build Artifact
      uses: actions/[email protected]
      with:
        name: application
        path: /home/runner/work/Foo/Foo/Foo/bin/Release/net5.0/publish/

Then we have a whole new job that runs on prem:

  deploy:
    needs: build
    runs-on: self-hosted
    
    steps:
    - name: Take application offline
      run: New-Item -Type File -Name app_offline.htm -Path E:\Foo -Force
      
    - name: Download new binaries over the top of the app
      uses: actions/download-artifact@v2
      with:
        name: application
        path: E:\Foo

    - name: Bring the app back online
      run: Remove-Item E:\Foo\app_offline.htm

So this creates an app_offline.htm file in our website folder (E:\Foo), then pulls the artifacts down from GitHub directly into that folder. When it's done, it deletes the app_offline.htm file and the site starts again.

It works a treat! Obviously keen to hear feedback from others if you think I'm doing something wrong, but I wanted to get that up here because this question ranks pretty highly when you search for "github actions deploy iis".

like image 105
Matt Hamilton Avatar answered Sep 19 '25 22:09

Matt Hamilton