generated from idea2app/Strapi-PNPM-Docker-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (60 loc) · 1.99 KB
/
deploy-production.yml
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
57
58
59
60
61
62
63
64
65
66
67
# reference:
# 1. https://github.com/docker/build-push-action/blob/master/docs/advanced/push-multi-registries.md
# 2. https://github.com/docker/build-push-action/blob/master/docs/advanced/share-image-jobs.md
name: Deploy to Production environment
on:
push:
tags:
- v*
env:
ARTIFACT_PATH: artifact.tar
BOX_NAME: strapi-server
BOX_URL: ohp/strapi-server
jobs:
deploy_docker_image:
name: Deploy Docker image
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Inject Environment variables
run: |
cat > .env <<EOF
${{ secrets.ENV_FILE }}
EOF
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Build Image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
tags: ${{ env.BOX_URL }}:latest
outputs: type=docker,dest=${{ env.ARTIFACT_PATH }}
- name: Pick Docker Compose
run: |
mkdir ./build
mv ${{ env.ARTIFACT_PATH }} .env ./docker-compose.yml ./start.sh ./build
- name: Transport Image
uses: garygrossgarten/github-action-scp@release
with:
local: ./build
remote: /tmp/${{ env.BOX_NAME }}
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.SSH_KEY }}
- name: Run Image
uses: garygrossgarten/github-action-ssh@release
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.SSH_KEY }}
command: |
cd /tmp/${{ env.BOX_NAME }}
mkdir -p ~/${{ env.BOX_NAME }}
mv .env docker-compose.yml start.sh ~/${{ env.BOX_NAME }}
cd ~/${{ env.BOX_NAME }}
chmod +x start.sh
echo '${{ secrets.SSH_KEY }}' | sudo -S ./start.sh /tmp/${{ env.BOX_NAME }}/${{ env.ARTIFACT_PATH }}