BUILD - test ci/cd #25
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 prod-minddaily-frontend | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build: | |
name: Build image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Build Docker image | |
run: | | |
docker build . --tag ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_IMAGE_NAME }} | |
- name: Publish Docker image | |
run: | | |
docker login -u ${{ secrets.DOCKER_REGISTRY }} -p ${{ secrets.DOCKER_HUB_TOKEN }} | |
docker push ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.IMAGE_NAME }} | |
deploy: | |
needs: build | |
name: Deploy image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install ssh keys | |
run: | | |
install -m 600 -D /dev/null ~/.ssh/id_rsa | |
echo "${{ secrets.SSHKEY }}" > ~/.ssh/id_rsa | |
ssh-keyscan -H ${{ secrets.HOST }} > ~/.ssh/known_hosts | |
- name: Connect and pull | |
run: ssh ${{ secrets.USERNAME }}@${{ secrets.HOST }} "cd ${{ secrets.WORK_DIR }} && docker compose pull && docker compose up -d && exit" | |
- name: Cleanup | |
run: rm -rf ~/.ssh | |
# - name: Save Docker image as tar file | |
# run: | | |
# docker save -o prod-minddaily-image.tar prod-minddaily-image:latest-prod | |
# chmod 664 prod-minddaily-image.tar | |
# - name: Transfer Docker image to remote server | |
# uses: appleboy/scp-action@master | |
# with: | |
# host: ${{ secrets.HOST }} | |
# port: ${{ secrets.PORT }} | |
# username: ${{ secrets.USERNAME }} | |
# key: ${{ secrets.SSHKEY }} | |
# source: "prod-minddaily-image.tar" | |
# target: "/home/ubuntu/production-images/" | |
# | |
# - name: Executing remote command | |
# uses: appleboy/ssh-action@master | |
# with: | |
# host: ${{ secrets.HOST }} | |
# username: ${{ secrets.USERNAME }} | |
# key: ${{ secrets.SSHKEY }} | |
# port: ${{ secrets.PORT}} | |
# source: '.' | |
# command_timeout: 10m | |
# script: ls |