updated all mardkdown files #4
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
name: Docker Build and Push | |
on: | |
push: | |
branches: [main] | |
paths: | |
- "frontend/**" | |
- "backend/**" | |
jobs: | |
determine-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
frontend_changed: ${{ steps.check.outputs.frontend }} | |
backend_changed: ${{ steps.check.outputs.backend }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Check for frontend changes | |
id: check | |
uses: dorny/paths-filter@v2 | |
with: | |
filters: | | |
frontend: | |
- 'frontend/**' | |
backend: | |
- 'backend/**' | |
build-and-push-frontend: | |
runs-on: ubuntu-latest | |
needs: [determine-changes] | |
if: ${{ needs.determine-changes.outputs.frontend_changed == 'true' }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Get current tags from DockerHub for frontend | |
id: get-tags | |
run: | | |
current_tags=$(curl -s -H "Authorization: Bearer ${{ secrets.DOCKERHUB_TOKEN }}" "https://hub.docker.com/v2/repositories/${{ secrets.DOCKERHUB_USERNAME }}/quash-max-frontend/tags?page_size=100" | jq -r '.results[].name') | |
latest_version=$(echo "$current_tags" | grep -Eo 'v[0-9]+' | sort -V | tail -1) | |
if [ -z "$latest_version" ]; then | |
new_version=v1 | |
else | |
new_version=v$(( ${latest_version:1} + 1 )) | |
fi | |
echo "New frontend version: $new_version" | |
echo "::set-output name=new_version::$new_version" | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Pull the latest image | |
run: docker pull ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-frontend:latest || true | |
- name: Tag the previous latest image | |
run: | | |
if docker inspect ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-frontend:latest; then | |
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-frontend:latest ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-frontend:${{ steps.get-tags.outputs.new_version }} | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-frontend:${{ steps.get-tags.outputs.new_version }} | |
fi | |
- name: Build and push frontend | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./frontend | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-frontend:latest | |
build-and-push-backend: | |
runs-on: ubuntu-latest | |
needs: [determine-changes] | |
if: ${{ needs.determine-changes.outputs.backend_changed == 'true' }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Get current tags from DockerHub for backend | |
id: get-tags | |
run: | | |
current_tags=$(curl -s -H "Authorization: Bearer ${{ secrets.DOCKERHUB_TOKEN }}" "https://hub.docker.com/v2/repositories/${{ secrets.DOCKERHUB_USERNAME }}/quash-max-backend/tags?page_size=100" | jq -r '.results[].name') | |
latest_version=$(echo "$current_tags" | grep -Eo 'v[0-9]+' | sort -V | tail -1) | |
if [ -z "$latest_version" ]; then | |
new_version=v1 | |
else | |
new_version=v$(( ${latest_version:1} + 1 )) | |
fi | |
echo "New backend version: $new_version" | |
echo "::set-output name=new_version::$new_version" | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'oracle' | |
- name: Build with Maven | |
run: mvn clean package | |
working-directory: ./backend | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Pull the latest image | |
run: docker pull ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-backend:latest || true | |
- name: Tag the previous latest image | |
run: | | |
if docker inspect ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-backend:latest; then | |
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-backend:latest ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-backend:${{ steps.get-tags.outputs.new_version }} | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-backend:${{ steps.get-tags.outputs.new_version }} | |
fi | |
- name: Build and push backend | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./backend | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/quash-max-backend:latest |