From b27b0a47da0e9f2e4ceeab18ca5246b334beb82d Mon Sep 17 00:00:00 2001 From: ShankarMounesh Date: Fri, 8 Apr 2022 02:33:08 +0530 Subject: [PATCH] github workflow --- .github/workflows/docker.yml | 149 +++++++++++++++++++++++++++++++++++ app/code/routes/web.php | 4 + 2 files changed, 153 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..11c72cc8 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,149 @@ +--- +name: Build and Push Image + +on: + # we want pull requests so we can build(test) but not push to image registry + pull_request: + branches: + - 'main' + # only build when important files change + paths-ignore: + # - 'README.md' + # - '.github/workflows/linter.yml' + - '.github/**' + - 'nginx/**' + - 'docker-compose.yml' + - 'docker-compose.dev.yml' + - 'docker-compose.prod.yml' + push: + branches: + - 'main' + # only build when important files change + paths-ignore: + - '.github/**' + - 'nginx/**' + - 'docker-compose.yml' + - 'docker-compose.dev.yml' + - 'docker-compose.prod.yml' + + + + # schedule: + # # re-run montly to keep image fesh with upstream base images + # - cron: '0 12 15 * *' + + + workflow_dispatch: + # run whenever we want! + workflow_call: + # allow reuse of this workflow in other repos + inputs: + dockerhub-enable: + description: Log in and push to Docker Hub + required: false + type: boolean + default: true + dockerhub-username: + description: Docker Hub username + required: false + type: string + default: buzzerburger + context: + description: Docker context (path) to start build from + required: false + type: string + default: . + target: + description: Build stage to target + required: false + type: string + file: + description: Name of Dockerfile (in relation to context path) + required: false + type: string + platforms: + description: Platforms to build for + required: false + type: string + default: linux/amd64,linux/arm64 + image-names: + description: A list of the account/repo names for docker build + required: false + type: string + default: | + ghcr.io/buzzerburger/test + secrets: + dockerhub-token: + description: Docker Hub token + required: false + + +jobs: + build-and-push-images: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + # we need qemu and buildx so we can build multiple platforms later + name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v1.2.0 + - + # BuildKit (used with `docker buildx`) is the best way to build images + name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Docker meta + id: docker_meta + uses: docker/metadata-action@v3.6.2 + with: + # list of Docker images to use as base name for tags + images: | + buzzerburger/test + ghcr.io/buzzerburger/test + flavor: | + latest=false + tags: | + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} + type=ref,event=pr,prefix=pr + - + # this will build the images, once per platform, + # then push to both Docker Hub and GHCR + name: Docker Build and Push + id: docker_build_and_push + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64 + context: app + target: ${{ inputs.target }} + file: ${{ inputs.file }} + builder: ${{ steps.buildx.outputs.name }} + # it uses github cache API for faster builds: + # https://github.com/crazy-max/docker-build-push-action/blob/master/docs/advanced/cache.md#cache-backend-api + cache-from: type=gha + cache-to: type=gha,mode=max + # for an approved pull_request, only push pr-specific tags + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + - + name: Show image digest + run: echo ${{ steps.docker_build_and_push.outputs.digest }} \ No newline at end of file diff --git a/app/code/routes/web.php b/app/code/routes/web.php index fd2810ab..75f2b5be 100644 --- a/app/code/routes/web.php +++ b/app/code/routes/web.php @@ -22,3 +22,7 @@ Route::resource('games', 'GameController'); Route::get('/hello', function () { return 'create'; }); + +Route::get('/shankar', function () { + return 'shankarr'; +});