feat: cd #5
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: Rust | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
build: | |
# runs-on: ubuntu-latest | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v4 # pull代码 | |
- name: Build src | |
run: | | |
cargo build --release --verbose | |
- name: Run tests | |
run: | | |
cargo test --verbose | |
- name: Docker login | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ secrets.REGISTRY_DOMAIN }} | |
username: ${{ secrets.REGISTRY_USERNAME }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: Build and push image | |
env: | |
REGISTRY: ${{ secrets.REGISTRY_DOMAIN }} | |
NAMESPACE: a2cd | |
IMAGE_NAME: rs-hello-world | |
IMAGE_TAG: latest | |
run: | | |
docker build -t $REGISTRY/$NAMESPACE/$IMAGE_NAME:$IMAGE_TAG . | |
docker push $REGISTRY/$NAMESPACE/$IMAGE_NAME:$IMAGE_TAG | |
- name: Setup SSH | |
env: | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
run: | | |
mkdir -p ~/.ssh/ && echo "$SSH_PRIVATE_KEY" > ~/.ssh/a2cd.key | |
cat >> ~/.ssh/config <<END | |
Host a2cd | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/a2cd.key | |
StrictHostKeyChecking no | |
END | |
- name: Deploy | |
run: ssh a2cd 'cd /usr/local/repo/rs-hello-world/ && docker-compose pull && docker-compose up -d' |