Skip to content

Commit

Permalink
Improve environment variables management and deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
oegea committed Feb 24, 2024
1 parent 9ef0084 commit 60e2fd9
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 43 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/deploy-on-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy on Server

on:
workflow_run:
workflows: ["Build and Push Docker image"]
branches: [main]
types:
- completed

jobs:
deploy:
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: Run container with the latest image
run: docker run -d --restart=always --env-file /root/passager-config/.env -p 3001-3002:3001-3002 oriolegea/passager-backend:latest
28 changes: 28 additions & 0 deletions .github/workflows/deploy-to-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and Push Docker image

on:
push:
branches:
- main
paths:
- 'backend/**'

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: oriolegea/passager-backend:latest
1 change: 0 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ RUN npm install
WORKDIR /usr/src/app
COPY ./authentication-service ./authentication-service
COPY ./documents-service ./documents-service
COPY ./.env ./.env
COPY ./run.sh ./run.sh

# Build the bundle
Expand Down
17 changes: 0 additions & 17 deletions backend/authentication-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion backend/authentication-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"license": "ISC",
"dependencies": {
"@useful-tools/docky-authentication-service": "^1.0.6",
"dotenv": "^16.0.2",
"debug": "^4.3.4",
"morgan": "^1.10.0",
"tslint": "^6.1.3"
Expand Down
3 changes: 0 additions & 3 deletions backend/authentication-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as dotenv from 'dotenv'
import {loadConfig, startAuthenticationService} from '@useful-tools/docky-authentication-service/dist'

dotenv.config({ path: '../.env' })

loadConfig({
commonAppName: process.env.COMMON_APP_NAME,
commonOrganizationName: process.env.COMMON_ORGANIZATION_NAME,
Expand Down
17 changes: 0 additions & 17 deletions backend/documents-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion backend/documents-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"dependencies": {
"@useful-tools/docky-documents-service": "^1.0.9",
"debug": "^4.3.4",
"dotenv": "^16.0.2",
"morgan": "^1.10.0",
"tslint": "^6.1.3"
},
Expand Down
3 changes: 0 additions & 3 deletions backend/documents-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as dotenv from 'dotenv'
import {getExpressApp, loadConfig, startDocumentsService, NativeEventBusRepository, TYPE_QUERY} from '@useful-tools/docky-documents-service/dist'
import {onGetOperationPermissions} from './onGetOperationPermissions'

dotenv.config({ path: '../.env' })

loadConfig({
commonAppName: process.env.COMMON_APP_NAME,
commonDisableCors: false,
Expand Down

0 comments on commit 60e2fd9

Please sign in to comment.