[IMP] Update #8
This file contains hidden or 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: pipeline | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
jobs: | |
run-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12' | |
- name: Install dependencies | |
run: | | |
pip install poetry | |
poetry install | |
# - name: Run tests | |
# run: | | |
# poetry run pytest -v --import-mode=importlib | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
# needs: | |
# - run-tests | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: | | |
ghcr.io/mart337i/deploy-it.dk:latest | |
ghcr.io/mart337i/deploy-it.dk:${{ github.sha }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: | |
- build-and-push-image | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Create env file | |
run: | | |
echo "GIT_COMMIT_HASH=${{ github.sha }}" > ./envfile | |
- name: Verify deployment files | |
run: | | |
test -f compose.yaml || (echo "compose.yaml missing!" && exit 1) | |
- name: Verify image exists | |
run: | | |
echo "Checking for image on registry..." | |
curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/user/packages/container/deploy-it.dk/versions | |
- name: Verify deployment files | |
run: | | |
echo "Contents of compose.yaml:" | |
cat compose.yaml | |
echo "Contents of envfile:" | |
cat ./envfile | |
- name: Test SSH connectivity | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.DOCKER_SSH_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.DOCKER_USER }}@${{ secrets.DOCKER_HOST }} "docker info" | |
- name: Docker Stack Deploy with Debug | |
uses: cssnr/[email protected] | |
with: | |
name: deploy-it.dk | |
file: compose.yaml | |
host: ${{ secrets.DOCKER_HOST }} | |
port: ${{ secrets.DOCKER_PORT }} | |
user: ${{ secrets.DOCKER_USER }} | |
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} | |
registry_host: 'ghcr.io' | |
registry_user: mart337i | |
registry_pass: ${{ secrets.GHCR_PASS }} | |
detach: false # This will show more detailed output | |
registry_auth: true # This adds --with-registry-auth flag | |
env_file: ./envfile | |
args: "--remove-orphans --force-recreate --verbose" # Try adding verbose flag |