Skip to content

Commit 275e380

Browse files
authored
Merge pull request #5 from GaryPWhite/GaryPWhite-include-docker
Create docker-publish.yml
2 parents f5d1403 + 07407ba commit 275e380

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

.github/workflows/docker-publish.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
# Publish `master` as Docker `latest` image.
6+
branches:
7+
- master
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
# Run tests for any PRs.
14+
pull_request:
15+
16+
env:
17+
# TODO: Change variable to your image's name.
18+
IMAGE_NAME: image
19+
20+
jobs:
21+
# Run tests.
22+
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
23+
test:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
29+
- name: Run tests
30+
run: |
31+
if [ -f docker-compose.test.yml ]; then
32+
docker-compose --file docker-compose.test.yml build
33+
docker-compose --file docker-compose.test.yml run sut
34+
else
35+
docker build . --file dockerfile
36+
fi
37+
38+
# Push image to GitHub Packages.
39+
# See also https://docs.docker.com/docker-hub/builds/
40+
push:
41+
# Ensure test job passes before pushing image.
42+
needs: test
43+
44+
runs-on: ubuntu-latest
45+
if: github.event_name == 'push'
46+
47+
steps:
48+
- uses: actions/checkout@v2
49+
50+
- name: Build image
51+
run: docker build . --file dockerfile --tag $IMAGE_NAME
52+
53+
- name: Log into registry
54+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
55+
56+
- name: Push image
57+
run: |
58+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
59+
60+
# Change all uppercase to lowercase
61+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
62+
63+
# Strip git ref prefix from version
64+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
65+
66+
# Strip "v" prefix from tag name
67+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
68+
69+
# Use Docker `latest` tag convention
70+
[ "$VERSION" == "master" ] && VERSION=latest
71+
72+
echo IMAGE_ID=$IMAGE_ID
73+
echo VERSION=$VERSION
74+
75+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
76+
docker push $IMAGE_ID:$VERSION

docker-compose.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3.8"
2+
3+
# Define the Docker Compose services that are available to build and run.
4+
services:
5+
tag-your-git:
6+
image: garypwhite/tag-your-git
7+
build:
8+
dockerfile: dockerfile
9+
context: .
10+
ports:
11+
- 8080:8080

dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.15.6-alpine
2+
3+
ENV TYG_ENTERPRISE_URL="https://replace.me.with.github.or.internal.url"
4+
ENV TYG_TAGS='{{paths: ["README.md"], tags: ["edits-readme"]}}'
5+
ENV TYG_GIT_API_KEY="REPLACE_ME"
6+
ENV TYG_WEBHOOK_SECRET_KEY="REPLACE_ME"
7+
8+
# for no reason
9+
EXPOSE 8080
10+
11+
WORKDIR /app
12+
COPY ./ /app
13+
14+
RUN rm -rf .git && \
15+
go install .
16+
17+
FROM alpine:3.12.3
18+
COPY --from=0 /go/bin/tag-your-git /usr/local/bin/
19+
20+
CMD ["tag-your-git"]

0 commit comments

Comments
 (0)