4 create e2 e test in pipeline #82
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: Pipeline | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'dev' | |
pull_request: | |
types: [ opened, synchronize, reopened ] | |
workflow_dispatch: | |
jobs: | |
publish-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: determine version | |
run: | | |
VERSION=$(cat VERSION | tr -d ' \t\n\r') | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
- name: Login to Docker Hub | |
if: contains('refs/heads/main', github.ref) || contains('refs/heads/dev', github.ref) | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ vars.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- uses: docker/setup-buildx-action@v3 | |
- name: Build and push dev | |
if: contains('refs/heads/dev', github.ref) | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker | |
push: ${{ contains('refs/heads/main', github.ref) }} | |
tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:dev | |
platforms: linux/amd64,linux/arm/v7,linux/arm64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Build and push main | |
if: contains('refs/heads/main', github.ref) | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker | |
push: true | |
tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest, ${{ vars.DOCKER_HUB_USERNAME }}/backup:${{ env.VERSION }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
publish-dockerhub-description: | |
if: contains('refs/heads/main', github.ref) | |
needs: | |
- publish-docker-image | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update Dockerhub description | |
uses: peter-evans/dockerhub-description@v4 | |
with: | |
username: ${{ vars.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
repository: ${{ vars.DOCKER_HUB_USERNAME }}/backup | |
readme-filepath: ./README.md | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Generate SSH Key Pair | |
run: | | |
mkdir -p sftp-keys | |
ssh-keygen -t rsa -b 2048 -f sftp-keys/id_rsa -q -N "" | |
chmod 600 sftp-keys/id_rsa | |
- name: Start SFTP Server with Mounts | |
run: | | |
docker run -d --name fake-sftp \ | |
-p 2222:22 \ | |
-v $(pwd)/sftp-keys/id_rsa.pub:/home/test/.ssh/keys/id_rsa.pub:ro \ | |
-v $(pwd)/sftp-data:/home/test/uploads \ | |
atmoz/sftp test::1001 | |
- name: Wait for SFTP server to be ready | |
run: | | |
for i in {1..10}; do | |
if nc -z localhost 2222; then | |
echo "SFTP server is up!" | |
exit 0 | |
fi | |
echo "Waiting for SFTP server..." | |
sleep 2 | |
done | |
echo "SFTP server did not start in time" && exit 1 | |
- name: Create test files | |
run: | | |
mkdir -p test-data | |
echo "File 1 content" > test-data/file1.txt | |
echo "File 2 content" > test-data/file2.txt | |
echo "File 3 content" > test-data/file3.txt | |
- name: Build for testing | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker | |
push: false | |
tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest | |
platforms: linux/amd64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: prepare test.env | |
run: | | |
echo "ENV_SSH_PRIVATE_KEY_BASE64=$(cat $(pwd)/sftp-keys/id_rsa | base64 -w 0)" >> test.env | |
- name: Run Backup Container | |
run: | | |
./run_backup.sh && sleep 25 && exit 0 |