Skip to content

Commit a55b40b

Browse files
committed
Add CI/CD
1 parent a4b18bd commit a55b40b

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

.github/workflows/branch.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Deploy to branch
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- preprod
8+
- develop
9+
10+
jobs:
11+
deploy:
12+
name: Deploy to branch
13+
runs-on: ubuntu-latest
14+
needs: validate
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Login to registry
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ${{ secrets.DOCKER_REGISTRY }}
22+
username: ${{ secrets.DOCKER_LOGIN }}
23+
password: ${{ secrets.DOCKER_PASSWD }}
24+
25+
- name: Build and push Docker image
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: .
29+
push: true
30+
tags: ${{ secrets.DOCKER_REGISTRY }}/wiki:${{ github.ref_name }}
31+
32+
- name: Configure SSH
33+
run: |
34+
mkdir -p ~/.ssh/
35+
echo "$SSH_KEY" > ~/.ssh/staging.key
36+
chmod 600 ~/.ssh/staging.key
37+
cat >>~/.ssh/config <<END
38+
Host staging
39+
HostName $SSH_HOST
40+
User $SSH_USER
41+
Port $SSH_PORT
42+
IdentityFile ~/.ssh/staging.key
43+
StrictHostKeyChecking no
44+
END
45+
env:
46+
SSH_USER: ${{ secrets.SSH_USER }}
47+
SSH_KEY: ${{ secrets.SSH_KEY }}
48+
SSH_HOST: ${{ secrets.SSH_HOST }}
49+
SSH_PORT: ${{ secrets.SSH_PORT }}
50+
51+
- name: Update branch environment
52+
run: |
53+
ssh staging 'export DOCKER_BRANCH=${{ github.ref_name }} DOCKER_REGISTRY=${{ secrets.DOCKER_REGISTRY }}
54+
cd /var/docker/wiki/${DOCKER_BRANCH}
55+
git pull origin ${DOCKER_BRANCH}
56+
docker compose --file docker-compose-branch.yml pull
57+
docker login -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWD }} ${DOCKER_REGISTRY}
58+
HOSTNAME=${{ github.ref_name == 'main' && 'wiki.realtoken.community' || 'wiki.${DOCKER_BRANCH}.realtoken.community' }} \
59+
docker compose --project-name ${{ github.ref_name }}-wiki --file docker-compose-branch.yml up -d'

docker-compose-branch.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
app:
3+
image: ${DOCKER_REGISTRY}/wiki:${DOCKER_BRANCH}
4+
container_name: ${DOCKER_BRANCH}-wiki
5+
networks:
6+
- traefik-realt
7+
labels:
8+
- 'traefik.enable=true'
9+
- 'traefik.http.routers.wiki-${DOCKER_BRANCH}.rule=Host(`${HOSTNAME}`)'
10+
- 'traefik.http.routers.wiki-${DOCKER_BRANCH}.entrypoints=websecure'
11+
restart: always
12+
13+
networks:
14+
traefik-realt:
15+
external: true

0 commit comments

Comments
 (0)