-
Notifications
You must be signed in to change notification settings - Fork 10
61 lines (53 loc) · 2.55 KB
/
deploy-on-server.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
name: Deploy on Server
on:
workflow_dispatch:
workflow_run:
workflows: ["Build and Push Docker image"]
branches: [main]
types:
- completed
jobs:
deploy:
environment: Backend production
runs-on: self-hosted
steps:
- name: Login to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- name: Remove all containers using the old image
run: |
docker container ls -q --filter ancestor=oriolegea/passager-backend:latest | xargs -r docker container stop
docker container ls -aq --filter ancestor=oriolegea/passager-backend:latest | xargs -r docker container rm
- name: Remove old images
run: |
docker image prune -af --filter "label=oriolegea/passager-backend"
- name: Pull latest Docker image
run: docker pull oriolegea/passager-backend:latest
- name: Calculate ports
run: |
echo "PORT_RANGE=${{ secrets.AUTH_PORT }}-${{ secrets.DOCS_PORT }}" >> $GITHUB_ENV
- name: Run container with the latest image
run: '
docker run -d --restart=always
--env AUTH_ALLOWED_DOMAINS="${{ secrets.AUTH_ALLOWED_DOMAINS }}"
--env AUTH_ALLOWED_EMAILS="${{ secrets.AUTH_ALLOWED_EMAILS }}"
--env AUTH_COLLECTION="${{ secrets.AUTH_COLLECTION }}"
--env AUTH_LIMIT_ACCESS_BY_EMAIL="${{ secrets.AUTH_LIMIT_ACCESS_BY_EMAIL }}"
--env AUTH_PORT="${{ secrets.AUTH_PORT }}"
--env AUTH_PUBLIC_URL="${{ secrets.AUTH_PUBLIC_URL }}"
--env AUTH_SMTP_HOST="${{ secrets.AUTH_SMTP_HOST }}"
--env AUTH_SMTP_PASSWORD="${{ secrets.AUTH_SMTP_PASSWORD }}"
--env AUTH_SMTP_PORT="${{ secrets.AUTH_SMTP_PORT }}"
--env AUTH_SMTP_SENDER="${{ secrets.AUTH_SMTP_SENDER }}"
--env AUTH_SMTP_USER="${{ secrets.AUTH_SMTP_USER }}"
--env COMMON_APP_NAME="${{ secrets.COMMON_APP_NAME }}"
--env COMMON_MONGODB_CONNECTION_STRING="${{ secrets.COMMON_MONGODB_CONNECTION_STRING }}"
--env COMMON_MONGODB_DATABASE="${{ secrets.COMMON_MONGODB_DATABASE }}"
--env COMMON_ORGANIZATION_NAME="${{ secrets.COMMON_ORGANIZATION_NAME }}"
--env COMMON_TOKEN_SECRET="${{ secrets.COMMON_TOKEN_SECRET }}"
--env DOCS_PORT="${{ secrets.DOCS_PORT }}"
--env DOCS_PUBLIC_URL="${{ secrets.DOCS_PUBLIC_URL }}"
-p ${{ env.PORT_RANGE }}:${{ env.PORT_RANGE }}
oriolegea/passager-backend:latest'