-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: .NET CI/CD | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
paths: | ||
- DataWorkerService | ||
- DataWorkerService.Tests | ||
- Common | ||
- Database | ||
|
||
jobs: | ||
build_test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: master | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '8.0.x' | ||
|
||
- name: Restore Dependencies | ||
run: dotnet restore | ||
|
||
- name: Build | ||
run: dotnet build -c Release --no-restore | ||
|
||
- name: Test | ||
run: dotnet test ./APITests/APITests.csproj -c Release --verbosity normal | ||
|
||
publish: | ||
needs: build_test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: master | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: stagecodes | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Build and Push Docker Image | ||
run: | | ||
docker build -t stagecodes/otr-api-staging . | ||
docker push stagecodes/otr-api-staging | ||
deploy: | ||
environment: Staging | ||
needs: publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: master | ||
- name: Create .env files | ||
run: | | ||
echo "${{ secrets.APP_ENV }}" > app.env | ||
echo "${{ secrets.DB_ENV }}" > db.env | ||
echo "${{ secrets.POSTGRES_EXPORTER_ENV }}" > postgres_exporter.env | ||
- name: Copy files to server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USER }} | ||
key: ${{ secrets.SSH_KEY }} | ||
source: "app.env,db.env,postgres_exporter.env,docker-compose-staging.yml,otel-collector-config.yml,prometheus.yml" | ||
target: "~/otr-api/" | ||
- name: Deploy | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USER }} | ||
key: ${{ secrets.SSH_KEY }} | ||
script: | | ||
cd ~/otr-api | ||
docker compose -f docker-compose-staging.yml pull | ||
docker compose -f docker-compose-staging.yml up -d --build |