File size: 1,340 Bytes
6c016cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
name: Docker Build on EC2 Instance

on:
  push:
    branches:
      - {{ branch_name }}

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: SSH and Execute Build on EC2
        uses: appleboy/ssh-action@master
        with:
          command_timeout: "60m"
          host: {{ host }}
          username: {{ username }}  # Usually 'ubuntu' or 'ec2-user'
          {% raw %}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          {% endraw %}
          script: |
            source activate pytorch
            nvidia-smi

            rm -rf {{ github_repo }} || true
            git clone https://github.com/{{ github_path }}
            cd {{ github_repo }}
            git checkout {{ branch_name }}
            git pull

            # Stop and remove existing container if it's running
            sudo docker stop {{ project_name }}-container || true
            sudo docker rm {{ project_name }}-container || true

            # Build the image
            sudo nvidia-docker build -t {{ project_name }} . || exit 1

            # Run the image
            sudo docker run -d -p 6092:6092 --gpus all --name {{ project_name }}-container \
              -e OPENAI_API_KEY={% raw %}${{ secrets.OPENAI_API_KEY }}{% endraw %} \
              {{ project_name }}