fix the hiring update #220
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
name: Deploy Official-website-backend to dev/prod Server | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
jobs: | |
deployment: | |
runs-on: ubuntu-latest | |
environment: dl-backend-env | |
env: | |
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
DOCKER_IMAGE_VERSION: dev-latest | |
DOCKER_IMAGE_NAME: dl-official-website-backend | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set environment variables based on branch | |
run: | | |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "DOCKER_IMAGE_VERSION=main-latest" >> $GITHUB_ENV | |
echo "BRANCH_NAME=main" >> $GITHUB_ENV | |
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then | |
echo "DOCKER_IMAGE_VERSION=dev-latest" >> $GITHUB_ENV | |
echo "BRANCH_NAME=dev" >> $GITHUB_ENV | |
fi | |
- name: Display current branch | |
run: | | |
echo "Current branch is $BRANCH_NAME" | |
- name: Build Docker image | |
run: | | |
docker build -t $DOCKER_USERNAME/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_VERSION . | |
- name: Push Docker image to registry | |
run: | | |
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin | |
docker push $DOCKER_USERNAME/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_VERSION | |
- name: SSH login to server and restart service on DEV server | |
uses: appleboy/ssh-action@master | |
if: contains(github.ref, 'dev') | |
with: | |
host: ${{ vars.DEV_SERVER_HOST }} #服务器ip地址 | |
username: ${{ vars.DEV_SERVER_USERNAME }} #服务器ssh用户名 | |
key: ${{ secrets.DEV_SSH_PRIVATE_KEY }} #服务器ssh私钥 | |
port: ${{ vars.DEV_PORT }} # 服务器ssh端口(默认22) | |
script: | | |
cd /root/Official-website-backend | |
docker compose pull | |
docker-compose down && docker-compose up -d | |
- name: SSH login to server and restart service on PROD server | |
uses: appleboy/ssh-action@master | |
if: contains(github.ref, 'main') | |
with: | |
host: ${{ vars.PROD_SERVER_HOST }} #服务器ip地址 | |
username: ${{ vars.PROD_SERVER_USERNAME }} #服务器ssh用户名 | |
key: ${{ secrets.PROD_SSH_PRIVATE_KEY }} #服务器ssh私钥 | |
port: ${{ vars.PROD_PORT }} # 服务器ssh端口(默认22) | |
script: | | |
cd /root/Official-website-backend | |
docker compose pull | |
docker-compose down && docker-compose up -d |