Deploy on Production #3
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 on Production | |
on: | |
workflow_run: | |
workflows: ["Build and Test"] | |
branches: [main] | |
types: | |
- completed | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- uses: docker/setup-buildx-action@v2 | |
- name: Build Docker Image and Push to DockerHub | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/tri-game:mb${{ github.run_number }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Render Deployment Pod Template | |
uses: chuhlomin/render-template@v1.6 | |
with: | |
template: deployment/prod/pod.yaml | |
result_path: deployment/prod/pod.yaml | |
vars: | | |
imageTag: mb${{ github.run_number }} | |
- name: Deploy to Production server | |
uses: easingthemes/ssh-deploy@main | |
env: | |
SOURCE: "deployment/prod/" | |
TARGET: "deployment/tri-game/" | |
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }} | |
REMOTE_HOST: ${{ secrets.REMOTE_HOST }} | |
REMOTE_USER: ${{ secrets.REMOTE_USER }} | |
SCRIPT_AFTER: | | |
podman pull docker.io/zakhio/tri-game:mb${{ github.run_number }} | |
escaped=$(systemd-escape ~/deployment/tri-game/pod.yaml) | |
systemctl --user restart podman-kube@$escaped.service | |
podman ps -a |