ci_cd #29
Workflow file for this run
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: ci_cd | |
on: | |
release: | |
types: [created] | |
env: | |
SSH_HOST: ${{secrets.SSH_HOST}} | |
SSH_USERNAME: ${{secrets.SSH_USERNAME}} | |
DEPLOY_DIR: ${{secrets.DEPLOY_DIR}} | |
SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Build & Push Image | |
run: | | |
docker login --username=${{secrets.DOCKER_USERNAME}} --password=${{secrets.DOCKER_PASSWORD}} ${{secrets.DOCKER_REGISTRY}} | |
docker build -t ${{secrets.DOCKER_REGISTRY}}/${{secrets.DOCKER_NAMESPACE}}/${{secrets.DOCKER_REPOSITORY}}:${{github.ref_name}} . | |
docker push ${{secrets.DOCKER_REGISTRY}}/${{secrets.DOCKER_NAMESPACE}}/${{secrets.DOCKER_REPOSITORY}}:${{github.ref_name}} | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: SSH Auth && Pull Image | |
run: | | |
ssh -V | |
eval $(ssh-agent -s) | |
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null | |
mkdir -p ~/.ssh | |
chmod 700 ~/.ssh | |
echo "PubkeyAcceptedKeyTypes +ssh-rsa" > ~/.ssh/config | |
ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts | |
chmod 644 ~/.ssh/known_hosts | |
docker pull ${{secrets.DOCKER_REGISTRY}}/${{secrets.DOCKER_NAMESPACE}}/${{secrets.DOCKER_REPOSITORY}}:${{github.ref_name}} | |
docker stop ${{secrets.DOCKER_CONTAINER_NAME}} | |
docker rm ${{secrets.DOCKER_CONTAINER_NAME}} | |
docker run -dp ${{secrets.HOST_PORT}}:${{secrets.CONTAINER_PORT}} --name ${{secrets.DOCKER_CONTAINER_NAME}} ${{secrets.DOCKER_NAMESPACE}}/${{secrets.DOCKER_REPOSITORY}}:${{github.ref_name}} |