Release 2.7.14 #50
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_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 && Deploy Image | |
run: | | |
ssh -V | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
cat >>~/.ssh/config <<END | |
Host remote | |
HostName ${{secrets.SSH_HOST}} | |
Port 22 | |
User ${{secrets.SSH_USERNAME}} | |
IdentityFile ~/.ssh/id_rsa | |
StrictHostKeyChecking no | |
END | |
cat >>~/remote.sh <<END | |
docker ps | |
docker login --username=${{secrets.DOCKER_USERNAME}} --password=${{secrets.DOCKER_PASSWORD}} ${{secrets.DOCKER_REGISTRY}} | |
docker pull ${{secrets.DOCKER_REGISTRY}}/${{secrets.DOCKER_NAMESPACE}}/${{secrets.DOCKER_REPOSITORY}}:${{github.ref_name}} | |
echo "Stopping container" | |
docker stop ${{secrets.DOCKER_CONTAINER_NAME}} | |
echo "Removing container" | |
docker rm ${{secrets.DOCKER_CONTAINER_NAME}} | |
echo "Creating new container" | |
docker run -dp ${{secrets.HOST_PORT}}:${{secrets.CONTAINER_PORT}} --name ${{secrets.DOCKER_CONTAINER_NAME}} ${{secrets.DOCKER_REGISTRY}}/${{secrets.DOCKER_NAMESPACE}}/${{secrets.DOCKER_REPOSITORY}}:${{github.ref_name}} | |
echo "Done" | |
END | |
ssh remote < ~/remote.sh | |
shell: bash |