Skip to content

Commit

Permalink
Feat: use specific commit for Docker image (#298)
Browse files Browse the repository at this point in the history
To avoid mismatching commit when re-running workflow builds
  • Loading branch information
Loyalsoldier committed Apr 2, 2021
1 parent 00093a2 commit c9cbcbe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2

- name: Setup QEMU
uses: docker/setup-qemu-action@v1

Expand All @@ -32,8 +29,10 @@ jobs:
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
Expand All @@ -44,6 +43,7 @@ jobs:
--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=${ref} \
--file Dockerfile .
test:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/docker-nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2

- name: Setup QEMU
uses: docker/setup-qemu-action@v1

Expand All @@ -30,12 +27,14 @@ jobs:
run: |
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
echo ::set-output name=ref::${{ github.sha }}
- 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 }}:nightly" \
--build-arg REF=${ref} \
--file Dockerfile .
test:
Expand Down
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
FROM golang:alpine AS builder
WORKDIR /
ARG REF
RUN apk add git make &&\
git clone https://github.com/p4gefau1t/trojan-go.git &&\
cd trojan-go &&\
git clone https://github.com/p4gefau1t/trojan-go.git
RUN if [[ -z "${REF}" ]]; then \
echo "No specific commit provided, use the latest one." \
;else \
echo "Use commit ${REF}" &&\
cd trojan-go &&\
git checkout ${REF} \
;fi
RUN cd trojan-go &&\
make &&\
wget https://github.com/v2fly/domain-list-community/raw/release/dlc.dat -O build/geosite.dat &&\
wget https://github.com/v2fly/geoip/raw/release/geoip.dat -O build/geoip.dat
Expand Down

0 comments on commit c9cbcbe

Please sign in to comment.