fix: deploy.yaml
This commit is contained in:
@@ -15,16 +15,22 @@ env:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
sha_short: ${{ steps.vars.outputs.sha_short }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set short SHA
|
||||
id: vars
|
||||
run: echo "sha_short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
IMAGE_BASE="${{ secrets.REGISTRY_USER }}/${{ env.DOCKERHUB_REPO }}"
|
||||
docker build \
|
||||
--build-arg VITE_API_BASE_URL="${{ env.VITE_API_BASE_URL }}" \
|
||||
-t "$IMAGE_BASE:${{ github.sha }}" \
|
||||
-t "$IMAGE_BASE:${{ steps.vars.outputs.sha_short }}" \
|
||||
-t "$IMAGE_BASE:latest" .
|
||||
|
||||
push:
|
||||
@@ -34,21 +40,23 @@ jobs:
|
||||
- name: Login and push to Docker Hub
|
||||
run: |
|
||||
IMAGE_BASE="${{ secrets.REGISTRY_USER }}/${{ env.DOCKERHUB_REPO }}"
|
||||
SHA="${{ needs.build.outputs.sha_short }}"
|
||||
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||
docker push "$IMAGE_BASE:${{ github.sha }}"
|
||||
docker push "$IMAGE_BASE:$SHA"
|
||||
docker push "$IMAGE_BASE:latest"
|
||||
docker logout
|
||||
|
||||
deploy:
|
||||
needs: push
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Pull & run new container
|
||||
- name: Pull and run new container
|
||||
run: |
|
||||
IMAGE_BASE="${{ secrets.REGISTRY_USER }}/${{ env.DOCKERHUB_REPO }}"
|
||||
SHA="${{ needs.build.outputs.sha_short }}"
|
||||
|
||||
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||
docker pull "$IMAGE_BASE:${{ github.sha }}"
|
||||
docker pull "$IMAGE_BASE:$SHA"
|
||||
docker logout
|
||||
|
||||
docker stop "${{ env.CONTAINER_NAME }}" 2>/dev/null || true
|
||||
@@ -58,8 +66,8 @@ jobs:
|
||||
--name "${{ env.CONTAINER_NAME }}" \
|
||||
--restart unless-stopped \
|
||||
-p "${{ env.HOST_PORT }}:${{ env.CONTAINER_PORT }}" \
|
||||
"$IMAGE_BASE:${{ github.sha }}"
|
||||
"$IMAGE_BASE:$SHA"
|
||||
|
||||
docker images "$IMAGE_BASE" --format '{{.Repository}}:{{.Tag}}' \
|
||||
| grep -v -e ':latest$' -e ":${{ github.sha }}$" \
|
||||
| grep -v -e ':latest$' -e ":$SHA$" \
|
||||
| xargs -r docker rmi || true
|
||||
Reference in New Issue
Block a user