diff options
| author | IwanIDev <iwan@iwani.dev> | 2026-03-04 16:30:55 +0000 |
|---|---|---|
| committer | IwanIDev <iwan@iwani.dev> | 2026-03-04 16:30:55 +0000 |
| commit | be721cffd0fc55ef665912ceec8edcb2e37ca326 (patch) | |
| tree | 98d48da5623a337afbe82c3a74a56df576215155 | |
| parent | 042bb9063c469406d5f59282ab94e95e8cdf401e (diff) | |
Add Docker deployment configuration and stack definition
| -rw-r--r-- | .github/workflows/docker_build.yml | 46 | ||||
| -rw-r--r-- | docker-stack.yml | 26 |
2 files changed, 71 insertions, 1 deletions
diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml index ea36e7e..01e8e50 100644 --- a/.github/workflows/docker_build.yml +++ b/.github/workflows/docker_build.yml @@ -50,4 +50,48 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha - cache-to: type=gha,mode=max
\ No newline at end of file + cache-to: type=gha,mode=max + + deploy: + needs: build + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup SSH key for Docker context + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key + chmod 600 ~/.ssh/deploy_key + ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts + + - name: Create Docker context + env: + DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} + DEPLOY_USER: ${{ secrets.DEPLOY_USER }} + DEPLOY_PORT: ${{ secrets.DEPLOY_PORT || 22 }} + run: | + docker context create remote --docker "host=ssh://$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PORT" + docker context use remote + docker context ls + + - name: Log in to GitHub Container Registry on remote + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker --context remote login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin + + - name: Deploy stack to remote server + env: + IMAGE_NAME: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + STACK_NAME: vite-portfolio + run: | + # Deploy the stack using the remote context + docker --context remote stack deploy -c docker-stack.yml --with-registry-auth $STACK_NAME + + # Wait for services to be ready + sleep 10 + + # Display stack services status + docker --context remote stack services $STACK_NAME
\ No newline at end of file diff --git a/docker-stack.yml b/docker-stack.yml new file mode 100644 index 0000000..98d473f --- /dev/null +++ b/docker-stack.yml @@ -0,0 +1,26 @@ +version: '3.8' + +services: + web: + image: ${IMAGE_NAME} + ports: + - "80:80" + deploy: + replicas: 2 + update_config: + parallelism: 1 + delay: 10s + order: start-first + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + labels: + - "app=vite-portfolio" + networks: + - portfolio-network + +networks: + portfolio-network: + driver: overlay |
