-
Notifications
You must be signed in to change notification settings - Fork 1.7k
59 lines (53 loc) · 1.86 KB
/
docker-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
on:
push:
branches:
- master
paths-ignore:
- "**.md"
- "docs/**"
tags:
- "v*.*.*"
name: docker-build
jobs:
build:
if: github.repository == 'p4gefau1t/trojan-go'
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Prepare
id: prepare
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo ::set-output name=version::${GITHUB_REF#refs/tags/}
echo ::set-output name=ref::${GITHUB_REF#refs/tags/}
else
echo ::set-output name=version::snapshot
echo ::set-output name=ref::${{ github.sha }}
fi
echo ::set-output name=docker_platforms::linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
echo ::set-output name=docker_image::${{ secrets.DOCKER_USERNAME }}/trojan-go
- name: Build and push docker image
run: |
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=true" \
--tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \
--tag "${{ steps.prepare.outputs.docker_image }}:latest" \
--build-arg REF=${{ steps.prepare.outputs.ref }} \
--file Dockerfile .
test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Test docker image
run: |
docker run --rm --entrypoint /usr/local/bin/trojan-go ${{ secrets.DOCKER_USERNAME }}/trojan-go -version