diff --git a/.github/workflows/deploy-on-server.yml b/.github/workflows/deploy-on-server.yml new file mode 100644 index 0000000..34c5dd6 --- /dev/null +++ b/.github/workflows/deploy-on-server.yml @@ -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 diff --git a/.github/workflows/deploy-to-dockerhub.yml b/.github/workflows/deploy-to-dockerhub.yml new file mode 100644 index 0000000..eaba170 --- /dev/null +++ b/.github/workflows/deploy-to-dockerhub.yml @@ -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 diff --git a/backend/Dockerfile b/backend/Dockerfile index 4ad25e4..12c1c43 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -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 diff --git a/backend/authentication-service/package-lock.json b/backend/authentication-service/package-lock.json index d41b8e4..974c01c 100644 --- a/backend/authentication-service/package-lock.json +++ b/backend/authentication-service/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "@useful-tools/docky-authentication-service": "^1.0.6", "debug": "^4.3.4", - "dotenv": "^16.0.2", "morgan": "^1.10.0", "tslint": "^6.1.3" }, @@ -3645,17 +3644,6 @@ "node": ">=6.0.0" } }, - "node_modules/dotenv": { - "version": "16.1.4", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", - "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/motdotla/dotenv?sponsor=1" - } - }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", @@ -10934,11 +10922,6 @@ "esutils": "^2.0.2" } }, - "dotenv": { - "version": "16.1.4", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", - "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==" - }, "ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", diff --git a/backend/authentication-service/package.json b/backend/authentication-service/package.json index 95f17c3..2c7a4f6 100644 --- a/backend/authentication-service/package.json +++ b/backend/authentication-service/package.json @@ -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" diff --git a/backend/authentication-service/src/index.ts b/backend/authentication-service/src/index.ts index 68be844..620a669 100644 --- a/backend/authentication-service/src/index.ts +++ b/backend/authentication-service/src/index.ts @@ -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, diff --git a/backend/documents-service/package-lock.json b/backend/documents-service/package-lock.json index 290f01d..cda7be4 100644 --- a/backend/documents-service/package-lock.json +++ b/backend/documents-service/package-lock.json @@ -11,7 +11,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" }, @@ -3614,17 +3613,6 @@ "node": ">=6.0.0" } }, - "node_modules/dotenv": { - "version": "16.1.4", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", - "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/motdotla/dotenv?sponsor=1" - } - }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", @@ -10840,11 +10828,6 @@ "esutils": "^2.0.2" } }, - "dotenv": { - "version": "16.1.4", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", - "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==" - }, "ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", diff --git a/backend/documents-service/package.json b/backend/documents-service/package.json index 4b66a64..5720900 100644 --- a/backend/documents-service/package.json +++ b/backend/documents-service/package.json @@ -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" }, diff --git a/backend/documents-service/src/index.ts b/backend/documents-service/src/index.ts index 9ef2906..8e82601 100644 --- a/backend/documents-service/src/index.ts +++ b/backend/documents-service/src/index.ts @@ -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,