feature/setup-workflow-pipeline: Extend and improve deploy step #5
@ -1,102 +1,89 @@
|
|||||||
name: Full Build and Docker Push Workflow
|
name: Full Build and Docker Push Workflow
|
||||||
run-name: ${{ gitea.actor }} is running a full build and Docker push workflow
|
run-name: ${{ gitea.actor }} is running a full build and Docker push workflow
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Builder:
|
Builder:
|
||||||
runs-on: catthacker-ubuntu-latest
|
runs-on: catthacker-ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Info
|
- name: Info
|
||||||
run: |
|
run: |
|
||||||
echo "Triggered by ${{ gitea.event_name }} event"
|
echo "Triggered by ${{ gitea.event_name }} event"
|
||||||
echo "Branch: ${{ gitea.ref }}"
|
echo "Branch: ${{ gitea.ref }}"
|
||||||
echo "Repository: ${{ gitea.repository }}"
|
echo "Repository: ${{ gitea.repository }}"
|
||||||
|
|
||||||
- name: Update apt-get and install Maven
|
- name: Update apt-get and install Maven
|
||||||
run: |
|
run: |
|
||||||
apt-get update -y
|
apt-get update -y
|
||||||
apt-get install -y maven
|
apt-get install -y maven
|
||||||
|
|
||||||
- name: Clone the repository
|
- name: Clone the repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Java
|
- name: Set up Java
|
||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build with Maven
|
||||||
run: |
|
run: |
|
||||||
java -version
|
java -version
|
||||||
mvn -version
|
mvn -version
|
||||||
mvn -B clean test -Dspring.profiles.active=test
|
mvn -B clean test -Dspring.profiles.active=test
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
#Build Docker image - Images must follow this naming convention: - {registry}/{owner}/{image}
|
#Build Docker image - Images must follow this naming convention: - {registry}/{owner}/{image}
|
||||||
- name: Build Docker image
|
- name: Build Docker image
|
||||||
env:
|
env:
|
||||||
GITEA_REGISTRY_URL: ${{ vars.REGISTRY_URL }}
|
GITEA_REGISTRY_URL: ${{ vars.REGISTRY_URL }}
|
||||||
OWNER: ${{ gitea.actor }}
|
OWNER: ${{ gitea.actor }}
|
||||||
IMAGE_NAME: my-app
|
IMAGE_NAME: my-app
|
||||||
run: |
|
run: |
|
||||||
#docker build -t $GITEA_REGISTRY_URL/$OWNER/my-app:latest .
|
#docker build -t $GITEA_REGISTRY_URL/$OWNER/my-app:latest .
|
||||||
# registry.domain.com/<username>/my-app:latest e.g. git.bepastem.com/eberen/my-app:latest
|
# registry.domain.com/<username>/my-app:latest e.g. git.bepastem.com/eberen/my-app:latest
|
||||||
docker build -t $GITEA_REGISTRY_URL/$OWNER/$IMAGE_NAME:latest .
|
docker build -t $GITEA_REGISTRY_URL/$OWNER/$IMAGE_NAME:latest .
|
||||||
|
|
||||||
- name: Build and push Docker image using Buildx
|
- name: Build and push Docker image using Buildx
|
||||||
env:
|
env:
|
||||||
GITEA_REGISTRY_URL: ${{ vars.REGISTRY_URL }}
|
GITEA_REGISTRY_URL: ${{ vars.REGISTRY_URL }}
|
||||||
IMAGE_NAME: my-app-backend
|
IMAGE_NAME: my-app-backend
|
||||||
APP_VERSION: v1.0.0
|
APP_VERSION: v1.0.0
|
||||||
OWNER: ${{ gitea.actor }}
|
OWNER: ${{ gitea.actor }}
|
||||||
LOGIN_TOKEN: ${{ secrets.LOGIN_TOKEN }}
|
LOGIN_TOKEN: ${{ secrets.LOGIN_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
docker buildx build --platform linux/amd64 -t $GITEA_REGISTRY_URL/$OWNER/$IMAGE_NAME:$APP_VERSION .
|
docker buildx build --platform linux/amd64 -t $GITEA_REGISTRY_URL/$OWNER/$IMAGE_NAME:$APP_VERSION .
|
||||||
#docker buildx build \
|
#docker buildx build \
|
||||||
# --platform linux/amd64 \
|
# --platform linux/amd64 \
|
||||||
# #-t $GITEA_REGISTRY_URL/$OWNER/$IMAGE_NAME:latest \
|
# #-t $GITEA_REGISTRY_URL/$OWNER/$IMAGE_NAME:latest \
|
||||||
# #--push \
|
# #--push \
|
||||||
# .
|
# .
|
||||||
|
|
||||||
- name: Push Docker image to Gitea Registry
|
- name: Push Docker image to Gitea Registry
|
||||||
env:
|
env:
|
||||||
GITEA_USERNAME: ${{ gitea.actor }}
|
GITEA_USERNAME: ${{ gitea.actor }}
|
||||||
LOGIN_TOKEN: ${{ secrets.LOGIN_TOKEN }}
|
LOGIN_TOKEN: ${{ secrets.LOGIN_TOKEN }}
|
||||||
GITEA_REGISTRY_URL: ${{ vars.REGISTRY_URL }}
|
GITEA_REGISTRY_URL: ${{ vars.REGISTRY_URL }}
|
||||||
run: |
|
run: |
|
||||||
# Login securely
|
# Login securely
|
||||||
echo "$LOGIN_TOKEN" | docker login $GITEA_REGISTRY_URL --username $GITEA_USERNAME --password-stdin
|
echo "$LOGIN_TOKEN" | docker login $GITEA_REGISTRY_URL --username $GITEA_USERNAME --password-stdin
|
||||||
docker push $GITEA_REGISTRY_URL/$GITEA_USERNAME/my-app:latest
|
docker push $GITEA_REGISTRY_URL/$GITEA_USERNAME/my-app:latest
|
||||||
docker logout $GITEA_REGISTRY_URL
|
docker logout $GITEA_REGISTRY_URL
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
run: |
|
run: |
|
||||||
docker images -a
|
docker images -a
|
||||||
docker system prune -f
|
docker system prune -f
|
||||||
docker images
|
docker images
|
||||||
echo "Cleanup done."
|
echo "Cleanup done."
|
||||||
|
|
||||||
- name: Prepare deploy script
|
|
||||||
run: |
|
|
||||||
mkdir -p .gitea/scripts
|
|
||||||
echo "echo Deploying..." > .gitea/scripts/deploy-backend.sh
|
|
||||||
chmod +x .gitea/scripts/deploy-backend.sh
|
|
||||||
|
|
||||||
- name: Deploy to server via deploy script
|
|
||||||
run: |
|
|
||||||
ls -a
|
|
||||||
ls .gitea/scripts/
|
|
||||||
chmod +x .gitea/scripts/deploy-backend.sh
|
|
||||||
#.gitea/scripts/deploy-backend.sh ${{ gitea.actor }} ${{ vars.REGISTRY_URL }} my-app-backend v1.0.0
|
|
||||||
.gitea/scripts/deploy-backend.sh
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
set -e # Exit immediately if a command exits with a non-zero status
|
set -e # Exit immediately if a command exits with a non-zero status
|
||||||
|
|
||||||
docker compose -f docker-compose-dev.yml down --remove-orphans --volumes
|
docker compose -f ../../../docker/docker-compose-dev.yml down --remove-orphans --volumes
|
||||||
|
|
||||||
docker system prune -f
|
docker system prune -f
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user