-
Notifications
You must be signed in to change notification settings - Fork 15
56 lines (50 loc) · 1.73 KB
/
production-deployment.yaml
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
46
47
48
49
50
51
52
53
54
55
56
name: PROD DEPLOYMENT WITH TAG
on:
push:
tags:
- 'v0.0.0'
env:
DEPLOY_TAG: ${{ github.ref_name }}
jobs:
PROD_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code from tag
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create .env and Dockerfile
run: |
echo "${{ secrets.DOCKER_FILE_PROD }}" > Dockerfile
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKER_IMAGE_NAME_PROD }} .
- name: Log in to Docker Hub
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME_PROD }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD_PROD }}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push ${{ secrets.DOCKER_IMAGE_NAME_PROD }}
- name: Deploy to Remote Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_NAME_PROD }}
username: ${{ secrets.USERNAME_PROD }}
key: ${{ secrets.SSH_KEY_PROD }}
port: ${{ secrets.PORT_PROD }}
script: |
TARGET_DIR="${{ secrets.TARGET_DIR_PROD }}"
ENVIRONMENT="$TARGET_DIR/.env
if [ -f "$ENVIRONMENT" ]; then
rm "$ENVIRONMENT"
fi
mkdir -p "$TARGET_DIR"
cat << EOF > "$ENVIRONMENT"
${{ secrets.PROD_ENV }}
EOF
cd ${{ secrets.TARGET_DIR_PROD }}
docker stop ${{ secrets.CONTAINER_NAME }}
docker rm -f ${{ secrets.CONTAINER_NAME }}
docker images --no-trunc -aqf "dangling=true" | xargs docker rmi
docker-compose up -d --force-recreate --no-deps