Skip to content

Commit 2dc594d

Browse files
committed
Add github action build script
1 parent 5719dd8 commit 2dc594d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Script taken from
2+
# https://github.com/darless1/gollum/blob/docker/.github/workflows/build-and-test.yml
3+
# MIT License
4+
5+
name: Build and Test Docker
6+
on: [push, pull_request]
7+
8+
env:
9+
CI_IMAGE: ${{ secrets.DOCKER_HUB_USERNAME }}/w2wiki:dev-${{ github.sha }}
10+
DEPLOY_IMAGE: ${{ secrets.DOCKER_HUB_USERNAME }}/w2wiki:latest
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check Out Repo
17+
uses: actions/checkout@v2
18+
- name: Login
19+
uses: docker/login-action@v1
20+
with:
21+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
22+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
23+
- name: Set up Docker Buildx
24+
id: buildx
25+
uses: docker/setup-buildx-action@v1
26+
- name: Cache docker layers
27+
uses: actions/cache@v2
28+
with:
29+
path: /tmp/.buildx-cache
30+
key: ${{ runner.os }}-buildx-${{ github.sha }}
31+
restore-keys: |
32+
${{ runner.os }}-buildx-
33+
34+
- name: Build and push
35+
id: docker_build
36+
uses: docker/build-push-action@v2
37+
with:
38+
context: ./
39+
file: ./Containerfile
40+
builder: ${{ steps.buildx.outputs.name }}
41+
push: true
42+
tags: ${{ env.CI_IMAGE }}
43+
cache-from: type=local,src=/tmp/.buildx-cache
44+
cache-to: type=local,dest=/tmp/.buildx-cache
45+
46+
- name: Image digest
47+
run: echo ${{ steps.docker_build.outputs.digest }}
48+
49+
deploy-on-master:
50+
runs-on: ubuntu-latest
51+
if: ${{ github.ref == 'refs/heads/master' }}
52+
needs: test
53+
steps:
54+
- name: Login
55+
uses: docker/login-action@v1
56+
with:
57+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
58+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
59+
60+
- name: Pull
61+
run: docker pull ${{ env.CI_IMAGE }}
62+
- name: Tag
63+
run: docker tag ${{ env.CI_IMAGE }} ${{ env.DEPLOY_IMAGE }}
64+
- name: Push
65+
run: docker push ${{ env.DEPLOY_IMAGE }}
66+

0 commit comments

Comments
 (0)