feat: cd #1
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_KEY: ${{ secrets.SSH_KEY }} | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/staging.key | |
chmod 600 ~/.ssh/staging.key | |
cat >>~/.ssh/config <<END | |
Host staging | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/staging.key | |
StrictHostKeyChecking no | |
END | |
- name: Update container | |
run: ssh staging 'cd /usr/local/repo/rs-hello-world/ && sudo docker-compose pull && sudo docker-compose -f docker-compose.yml up -d' |