diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fb5b34f Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/deployer.yaml b/.github/workflows/deployer.yaml deleted file mode 100644 index 2a0a72e..0000000 --- a/.github/workflows/deployer.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: Build and publish Deployer - -on: - workflow_dispatch: - push: - branches: - - main - paths: - - deployer/** - -jobs: - publish-docker-image: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Log in to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v3 - with: - images: 2xnone/deployer - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - type=raw,value=latest - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: ./deployer/ - file: ./deployer/Dockerfile - push: true - platforms: linux/amd64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..fc4940f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,74 @@ +name: Docker Image CI + +on: + release: + types: [created] + workflow_dispatch: + inputs: + component: + description: 'Component name (e.g., releaser, mongodump)' + required: true + version: + description: 'Version number (e.g., 0.1.0)' + required: true + pull_request: + branches: [ main ] + paths: + - '**/Dockerfile' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Extract component and semantic version + id: extract_info + run: | + if [[ "${{ github.event_name }}" == "release" ]]; then + TAG=${GITHUB_REF#refs/tags/} + COMPONENT=$(echo $TAG | cut -d'-' -f1) + SEMANTIC=$(echo $TAG | cut -d'-' -f2-) + elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + COMPONENT="${{ github.event.inputs.component }}" + SEMANTIC="${{ github.event.inputs.version }}" + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then + COMPONENT=$(echo "${{ github.event.pull_request.title }}" | grep -oP '^\w+' || echo "test") + SEMANTIC="pr-${{ github.event.pull_request.number }}" + fi + echo "::set-output name=COMPONENT::$COMPONENT" + echo "::set-output name=SEMANTIC::$SEMANTIC" + echo "::set-output name=WORKFLOW_NAME::$COMPONENT Docker Image CI" + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Check if Dockerfile exists + id: dockerfile_check + run: | + if [ -f "${{ steps.extract_info.outputs.COMPONENT }}/Dockerfile" ]; then + echo "::set-output name=EXISTS::true" + else + echo "::set-output name=EXISTS::false" + echo "No Dockerfile found for component ${{ steps.extract_info.outputs.COMPONENT }}" + exit 1 + fi + + - name: Build and push Docker image + if: steps.dockerfile_check.outputs.EXISTS == 'true' + uses: docker/build-push-action@v2 + with: + context: ./${{ steps.extract_info.outputs.COMPONENT }} + file: ./${{ steps.extract_info.outputs.COMPONENT }}/Dockerfile + push: ${{ github.event_name == 'release' }} + tags: | + ${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:${{ steps.extract_info.outputs.SEMANTIC }} + ${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:latest + + - name: Echo Workflow Name + run: | + echo "Current workflow name: ${{ steps.extract_info.outputs.WORKFLOW_NAME }}" diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..1131bf5 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu +RUN echo "test"