-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve environment variables management and deploy
- Loading branch information
Showing
9 changed files
with
61 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters