diff --git a/.github/workflows/beardedsamwise-c05-actions02.yaml b/.github/workflows/beardedsamwise-c05-actions02.yaml new file mode 100644 index 0000000..22fcf2f --- /dev/null +++ b/.github/workflows/beardedsamwise-c05-actions02.yaml @@ -0,0 +1,43 @@ +on: + pull_request: + paths: + - 'beardedsamwise/c05-actions-02/*' + +jobs: + build: + runs-on: ubuntu-latest + name: Push image to Docker Hub + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Log in to Docker Hub + working-directory: beardedsamwise/c05-actions-02/ + run: make login + env: + BEARDED_DOCKER: ${{ secrets.BEARDED_DOCKER }} + + - name: Build Docker image + working-directory: beardedsamwise/c05-actions-02/ + run: make build + + - name: Push image to Docker Hub + working-directory: beardedsamwise/c05-actions-02/ + run: make push + + - name: Create image ID variable + working-directory: beardedsamwise/c05-actions-02/ + run: make output + + - name: Comment PR with latest image ID + uses: thollander/actions-comment-pull-request@v1 + with: + message: 'The latest Docker image ID is: ${{ env.FULLIMAGEID }}' + GITHUB_TOKEN: ${{ secrets.BEARDED_KEY }} + + + + diff --git a/beardedsamwise/c05-actions-02/Dockerfile b/beardedsamwise/c05-actions-02/Dockerfile new file mode 100644 index 0000000..982e43a --- /dev/null +++ b/beardedsamwise/c05-actions-02/Dockerfile @@ -0,0 +1,2 @@ +FROM httpd:2.4.41 +RUN echo "This is my GH actions exercise" > /usr/local/apache2/htdocs/index.html \ No newline at end of file diff --git a/beardedsamwise/c05-actions-02/Makefile b/beardedsamwise/c05-actions-02/Makefile new file mode 100644 index 0000000..25664a3 --- /dev/null +++ b/beardedsamwise/c05-actions-02/Makefile @@ -0,0 +1,23 @@ +SHA = $(shell git rev-parse --short HEAD) +IMAGEID = "beardedsamwise/c05-actions02" +export BEARDED_DOCKER + +.PHONY: build +build: + @echo "BUILDING DOCKER IMAGE WITH TAG $(IMAGEID):$(SHA)" + docker build -t $(IMAGEID):$(SHA) . + +.PHONY: push +push: + @echo "PUSHING DOCKER IMAGE TO DOCKER HUB WITH TAG c03-make01:$(SHA)" + docker push $(IMAGEID):$(SHA) + +.PHONY: login +login: + echo "LOGGING IN TO DOCKER HUB..." + @echo $(BEARDED_DOCKER) | docker login --username beardedsamwise --password-stdin + +.PHONY: output +output: + echo "FULLIMAGEID=$(IMAGEID):$(SHA)" >> $(GITHUB_ENV) +