diff --git a/.github/workflows/gpavelar-gh-actions02-workflow.yaml b/.github/workflows/gpavelar-gh-actions02-workflow.yaml index a2f8a8f..81b2107 100644 --- a/.github/workflows/gpavelar-gh-actions02-workflow.yaml +++ b/.github/workflows/gpavelar-gh-actions02-workflow.yaml @@ -5,17 +5,29 @@ on: - master paths: 'gpavelar/c05-actions02/**' +defaults: + run: + working-directory: 'gpavelar/c05-actions02' + jobs: comment: name: Deploy - runs-on: ubuntu-18.04 - defaults: - run: - working-directory: 'gpavelar/c05-actions02' - + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set tag var + id: vars + run: | + echo ::set-output name=tag::$(git rev-parse --short HEAD) + echo ::set-output name=image::actions02 + - name: Docker build and tag - run: make docker-build + run: | + make docker-build + shell: bash - name: Docker Push Image env: @@ -24,16 +36,15 @@ jobs: - name: Comment Image and Short SHA uses: mshick/add-pr-comment@v1 - env: - GITHUB_TOKEN: ${{ secrets.GPAVELAR_PAT }} with: - message: "${{ env.IMAGE }}:${{ env.SHORT_SHA }}" + message: "${{ steps.vars.outputs.image }}:${{ steps.vars.outputs.tag }}" + repo-token: ${{ secrets.GPAVELAR_PAT }} + allow-repeats: false - - # uses: mshick/add-pr-comment@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GPAVELAR_PAT }} - # with: - # message: "Well done ${{ secrets.GPAVELAR_USERNAME }} ! This is a nice PR" - # repo-token-user-login: 'github-actions[bot]' - # allow-repeats: true \ No newline at end of file + - name: Comment + uses: mshick/add-pr-comment@v1 + with: + message: "Well done ${{ secrets.GPAVELAR_USERNAME }} ! This is a nice PR" + repo-token-user-login: 'github-actions[bot]' + repo-token: ${{ secrets.GPAVELAR_PAT }} + allow-repeats: false \ No newline at end of file diff --git a/gpavelar/c05-actions02/Dockerfile b/gpavelar/c05-actions02/Dockerfile index 982e43a..f111eed 100644 --- a/gpavelar/c05-actions02/Dockerfile +++ b/gpavelar/c05-actions02/Dockerfile @@ -1,2 +1,5 @@ FROM httpd:2.4.41 +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y git RUN echo "This is my GH actions exercise" > /usr/local/apache2/htdocs/index.html \ No newline at end of file diff --git a/gpavelar/c05-actions02/Makefile b/gpavelar/c05-actions02/Makefile index dc932a0..bd4ccc3 100644 --- a/gpavelar/c05-actions02/Makefile +++ b/gpavelar/c05-actions02/Makefile @@ -1,8 +1,8 @@ COMPOSE_PATH = docker-compose.yml COMPOSE_ENV = docker-compose -f ${COMPOSE_PATH} COMPOSE_RUN = ${COMPOSE_ENV} run --rm -SHORT_SHA=$(shell git rev-parse --short HEAD) -IMAGE ?= actions02 +export SHORT_SHA=$$(git rev-parse --short HEAD) +export IMAGE=actions02 DH_USERNAME ?= gpavelar ##+MAKEFILE HELPER @@ -23,24 +23,24 @@ build: ##+ Builds the compose containers. ##+ ##+ Docker build ##+ -.PHONY: docker-build docker-build: @echo "Building Docker Image ${IMAGE}:${SHORT_SHA}" - @docker build -t ${IMAGE}:${SHORT_SHA} . + @docker build -t ${IMAGE}:$(SHORT_SHA) . +.PHONY: docker-build ##+ ##+ Docker push image ##+ -.PHONY: docker-push docker-push: dh-login @echo "Publishing the container as ${DH_USERNAME}/${IMAGE}:${SHORT_SHA}" @docker tag ${IMAGE}:${SHORT_SHA} ${DH_USERNAME}/${IMAGE}:${SHORT_SHA} @docker push ${DH_USERNAME}/${IMAGE}:${SHORT_SHA} +.PHONY: docker-push ##+ ##+ DockerHub login ##+ -.PHONY: dh-login dh-login: @echo "Log in to a Docker registry" - @docker login --username ${DH_USERNAME} --password ${GPAVELAR_DH_TOKEN} \ No newline at end of file + @docker login --username ${DH_USERNAME} --password ${GPAVELAR_DH_TOKEN} +.PHONY: dh-login \ No newline at end of file diff --git a/gpavelar/c05-actions02/README-actions02.md b/gpavelar/c05-actions02/README-actions02.md index 19c21ff..9ae62e9 100644 --- a/gpavelar/c05-actions02/README-actions02.md +++ b/gpavelar/c05-actions02/README-actions02.md @@ -50,32 +50,50 @@ on: - master paths: 'gpavelar/c05-actions02/**' +defaults: + run: + working-directory: 'gpavelar/c05-actions02' + jobs: comment: name: Deploy - runs-on: ubuntu-18.04 - + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set tag var + id: vars + run: | + echo ::set-output name=tag::$(git rev-parse --short HEAD) + echo ::set-output name=image::actions02 + - name: Docker build and tag - working-directory: 'gpavelar/c05-actions02/' - run: make docker-build + run: | + make docker-build + shell: bash - name: Docker Push Image - working-directory: 'gpavelar/c05-actions02/' env: GPAVELAR_DH_TOKEN: ${{ secrets.GPAVELAR_DH_TOKEN }} run: make docker-push + - name: Comment Image and Short SHA uses: mshick/add-pr-comment@v1 + env: + IMAGE: "action02" + SHORT_SHA: "v1" with: - message: "${{ env.IMAGE }}:${{ env.SHORT_SHA }}" - + message: "${{ steps.vars.outputs.image }}:${{ steps.vars.outputs.tag }}" + repo-token: ${{ secrets.GPAVELAR_PAT }} + allow-repeats: true - # uses: mshick/add-pr-comment@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GPAVELAR_PAT }} - # with: - # message: "Well done ${{ secrets.GPAVELAR_USERNAME }} ! This is a nice PR" - # repo-token-user-login: 'github-actions[bot]' - # allow-repeats: true + - name: Comment + uses: mshick/add-pr-comment@v1 + with: + message: "Well done ${{ secrets.GPAVELAR_USERNAME }} ! This is a nice PR" + repo-token-user-login: 'github-actions[bot]' + repo-token: ${{ secrets.GPAVELAR_PAT }} + allow-repeats: false ``` \ No newline at end of file