Refactor backend deployment workflow to use environment variables for registry configuration and update deployment conditions to target dev branch
This commit is contained in:
parent
337e97128d
commit
26854dc4a1
1 changed files with 13 additions and 9 deletions
|
|
@ -9,6 +9,11 @@ on:
|
||||||
- 'Backend/**'
|
- 'Backend/**'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
|
||||||
|
REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
|
||||||
|
REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build Backend Docker Image
|
name: Build Backend Docker Image
|
||||||
|
|
@ -20,27 +25,26 @@ jobs:
|
||||||
- name: Login to Docker Registry
|
- name: Login to Docker Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ vars.DOCKER_REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ env.REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ env.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
config-inline: |
|
config-inline: |
|
||||||
[registry."${{ vars.DOCKER_REGISTRY }}"]
|
[registry."${{ env.REGISTRY }}"]
|
||||||
http = true
|
ca=["/etc/ssl/certs/ca-certificates.crt"]
|
||||||
insecure = true
|
|
||||||
|
|
||||||
- name: Extract metadata
|
- name: Extract metadata
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ${{ vars.DOCKER_REGISTRY }}/elearning-backend
|
images: ${{ env.REGISTRY }}/elearning-backend
|
||||||
tags: |
|
tags: |
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
type=sha,prefix=
|
type=sha,prefix=
|
||||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/dev' }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
|
|
@ -57,7 +61,7 @@ jobs:
|
||||||
name: Deploy Backend to Server
|
name: Deploy Backend to Server
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
needs: build
|
||||||
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
|
if: github.ref == 'refs/heads/dev'
|
||||||
steps:
|
steps:
|
||||||
- name: Remote Deploy
|
- name: Remote Deploy
|
||||||
uses: appleboy/ssh-action@v1.2.1
|
uses: appleboy/ssh-action@v1.2.1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue