Skip to content

Commit 4d4cec9

Browse files
added step to deploy to docker swarm
1 parent ecff058 commit 4d4cec9

File tree

2 files changed

+22
-56
lines changed

2 files changed

+22
-56
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ jobs:
1212
- name: Checkout repository
1313
uses: actions/checkout@v4
1414

15-
- name: Create env file in /server
16-
run: |
17-
mkdir -p server
18-
touch server/.env
19-
echo DATABASE_URI=${{ vars.DATABASE_URI }} >> server/.env
20-
cat server/.env # Verify the file is created
21-
2215
- name: Build Docker image
23-
run: docker build -t my-app:latest -t my-app:${{ github.sha }} -f server/Dockerfile server
16+
run: docker build -t nettleship-net-api:latest -f server/Dockerfile server
17+
18+
- name: Deploy to Docker Swarm
19+
run: |
20+
# Make sure Docker is available and the image is built
21+
docker pull nettleship-net-api:latest # (if needed, to ensure the latest is on the Pi)
22+
23+
# Deploy to Swarm
24+
docker stack deploy -c docker-compose.yml nettleship-net-api

server/compose.yaml

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,16 @@
1-
# Comments are provided throughout this file to help you get started.
2-
# If you need more help, visit the Docker Compose reference guide at
3-
# https://docs.docker.com/go/compose-spec-reference/
1+
version: "3.9"
42

5-
# Here the instructions define your application as a service called "server".
6-
# This service is built from the Dockerfile in the current directory.
7-
# You can add other services your application may depend on here, such as a
8-
# database or a cache. For examples, see the Awesome Compose repository:
9-
# https://github.com/docker/awesome-compose
103
services:
11-
server:
12-
build:
13-
context: .
14-
environment:
15-
NODE_ENV: production
4+
nettleship-net-api:
5+
image: nettleship-net-api:latest
6+
deploy:
7+
replicas: 1
8+
restart_policy:
9+
condition: none
10+
placement:
11+
constraints:
12+
- node.role == manager # This ensures the service runs only on the manager node (pi-1)
1613
ports:
17-
- 8000:8000
18-
19-
# The commented out section below is an example of how to define a PostgreSQL
20-
# database that your application can use. `depends_on` tells Docker Compose to
21-
# start the database before your application. The `db-data` volume persists the
22-
# database data between container restarts. The `db-password` secret is used
23-
# to set the database password. You must create `db/password.txt` and add
24-
# a password of your choosing to it before running `docker-compose up`.
25-
# depends_on:
26-
# db:
27-
# condition: service_healthy
28-
# db:
29-
# image: postgres
30-
# restart: always
31-
# user: postgres
32-
# secrets:
33-
# - db-password
34-
# volumes:
35-
# - db-data:/var/lib/postgresql/data
36-
# environment:
37-
# - POSTGRES_DB=example
38-
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
39-
# expose:
40-
# - 5432
41-
# healthcheck:
42-
# test: [ "CMD", "pg_isready" ]
43-
# interval: 10s
44-
# timeout: 5s
45-
# retries: 5
46-
# volumes:
47-
# db-data:
48-
# secrets:
49-
# db-password:
50-
# file: db/password.txt
51-
14+
- "3000:3000"
15+
volumes:
16+
- ./logs:/usr/src/app/logs

0 commit comments

Comments
 (0)