From 731b86bcd2325e2406be1da763119c6870edfd91 Mon Sep 17 00:00:00 2001 From: Alan Lima Date: Wed, 19 Aug 2020 20:12:36 +1000 Subject: [PATCH 1/2] add workflow to build and push image to docker hub --- .../workflows/gh-alanlima-pr-actions02.yml | 50 +++++++++++++++++++ alanlima/c05-actions02/Dockerfile | 6 +++ alanlima/c05-actions02/Makefile | 31 ++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 .github/workflows/gh-alanlima-pr-actions02.yml create mode 100644 alanlima/c05-actions02/Dockerfile create mode 100644 alanlima/c05-actions02/Makefile diff --git a/.github/workflows/gh-alanlima-pr-actions02.yml b/.github/workflows/gh-alanlima-pr-actions02.yml new file mode 100644 index 0000000..2c2874d --- /dev/null +++ b/.github/workflows/gh-alanlima-pr-actions02.yml @@ -0,0 +1,50 @@ +name: gh-alanlima-pr-actions02 + +on: + pull_request: + branches: + - master + paths: + - 'alanlima/c05-actions02/**/*' + +jobs: + push_image: + runs-on: ubuntu-20.04 + + steps: + - name: Code Checkout + uses: actions/checkout@v2 + + - name: Build and Push Image + working-directory: 'alanlima/c05-actions02' + env: + DOCKER_TOKEN: ${{ secrets.ALIMA_DOCKER_TOKEN }} + run: make all + + - name: Get DockerHub Tag Url + working-directory: 'alanlima/c05-actions02' + id: dockerhub + shell: bash + run: make ci_github_set_outputs + + - name: Add Comment + uses: jungwinter/comment@v1 + with: + type: create + issue_number: ${{ github.event.number }} + token: ${{ secrets.ALIMA_TOKEN }} + body: | + Well done **${{ secrets.ALIMA_NAME }}**, you are the best ๐ŸŽŠ๐ŸŽŠ๐ŸŽŠ + You wrote a fantastic code ๐Ÿงก๐Ÿงก๐Ÿงก๐Ÿงก + + **Here if the URL for the docker image that I kindly pushed to docker hub: ๐Ÿณ๐Ÿณ๐Ÿณ๐Ÿณ** + + **[${{ steps.dockerhub.outputs.image_name }}](${{ steps.dockerhub.outputs.url }})** + + ```bash + docker pull ${{ steps.dockerhub.outputs.image_name }} + ``` + + Looking forward to help you again ๐Ÿ˜œ + + ๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€ \ No newline at end of file diff --git a/alanlima/c05-actions02/Dockerfile b/alanlima/c05-actions02/Dockerfile new file mode 100644 index 0000000..d3b2289 --- /dev/null +++ b/alanlima/c05-actions02/Dockerfile @@ -0,0 +1,6 @@ +FROM httpd:2.4.41 + +LABEL maintainer="Alan Lima" +LABEL version="v1" + +RUN echo "This is my GH actions exercise" > /usr/local/apache2/htdocs/index.html \ No newline at end of file diff --git a/alanlima/c05-actions02/Makefile b/alanlima/c05-actions02/Makefile new file mode 100644 index 0000000..20de944 --- /dev/null +++ b/alanlima/c05-actions02/Makefile @@ -0,0 +1,31 @@ +DOCKER_REGISTRY?=alanrlima +IMAGE_NAME?=devops-c05-actions02 +COMMIT_SHA?=$(shell git rev-parse --short HEAD) + +build: + @docker build \ + -t ${DOCKER_REGISTRY}/${IMAGE_NAME}:${COMMIT_SHA}\ + -f Dockerfile . +.PHONY:build + +push: + @docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:${COMMIT_SHA} +.PHONY:push + +login: + docker login \ + --username ${DOCKER_REGISTRY} \ + --password ${DOCKER_TOKEN} +.PHONY:login + +dockerhub_url: + @echo "https://hub.docker.com/repository/docker/${DOCKER_REGISTRY}/${IMAGE_NAME}/tags?page=1&name=${COMMIT_SHA}" +.PHONY:dockerhub_url + +ci_github_set_outputs: + @echo "::set-output name=url::$(shell make dockerhub_url)" + @echo "::set-output name=image_name::${DOCKER_REGISTRY}/${IMAGE_NAME}:${COMMIT_SHA}" +.PHONY:ci_github_set_outputs + +all: login build push +.PHONY: all \ No newline at end of file From 94d419cbcf0344310bc7547fc73d03bdb7c7d974 Mon Sep 17 00:00:00 2001 From: Alan Lima Date: Wed, 19 Aug 2020 20:14:53 +1000 Subject: [PATCH 2/2] add some change --- alanlima/c05-actions02/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alanlima/c05-actions02/Dockerfile b/alanlima/c05-actions02/Dockerfile index d3b2289..1bb61c5 100644 --- a/alanlima/c05-actions02/Dockerfile +++ b/alanlima/c05-actions02/Dockerfile @@ -1,6 +1,6 @@ FROM httpd:2.4.41 LABEL maintainer="Alan Lima" -LABEL version="v1" +LABEL version="v2" RUN echo "This is my GH actions exercise" > /usr/local/apache2/htdocs/index.html \ No newline at end of file