Skip to content

Commit

Permalink
Merge pull request #14 from acelaya-forks/feature/gh-action-docker-build
Browse files Browse the repository at this point in the history
Feature/gh action docker build
  • Loading branch information
acelaya authored Jul 31, 2020
2 parents 1ac05fd + 659d758 commit 355ed84
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/docker-image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build docker image

on:
push:
branches:
- develop
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest
- name: Build the image
run: bash ./docker/build
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ jobs:
allow_failures:
- php: 'nightly'
include:
- name: "Docker publish"
if: NOT type = pull_request
# Overwrite all common steps that have to be different
before_install: echo "Before install"
install: sudo ./data/infra/ci/install-docker.sh
before_script: echo "Before script"
script: bash ./docker/build
after_success: echo "After success"
- name: "CI - 8.0"
php: 'nightly'
env:
Expand All @@ -47,7 +39,6 @@ jobs:
on:
tags: true

# Common steps for all jobs
before_install:
- echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- phpenv config-rm xdebug.ini || return 0
Expand Down
12 changes: 0 additions & 12 deletions data/infra/ci/install-docker.sh

This file was deleted.

30 changes: 11 additions & 19 deletions docker/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@

set -e

# PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64"
PLATFORMS="linux/amd64"
DOCKER_IMAGE="shlinkio/shlink"
BUILDX_VER=v0.4.1
export DOCKER_CLI_EXPERIMENTAL=enabled
PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64"
# PLATFORMS="linux/amd64"
DOCKER_IMAGE="shlinkio/lab"

mkdir -vp ~/.docker/cli-plugins/ ~/dockercache
curl --silent -L "https://github.com/docker/buildx/releases/download/${BUILDX_VER}/buildx-${BUILDX_VER}.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

docker buildx create --use

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

# If there is a tag, regardless the branch, build that docker tag and also "stable"
if [[ ! -z $TRAVIS_TAG ]]; then
TAGS="-t ${DOCKER_IMAGE}:${TRAVIS_TAG#?}"
# If ref is not develop, then this is a tag. Build that docker tag and also "stable"
if [[ "$GITHUB_REF" != *"develop"* ]]; then
TAGS="-t ${DOCKER_IMAGE}:${GITHUB_REF#?}"
# Push stable tag only if this is not an alpha or beta tag
[[ $TRAVIS_TAG != *"alpha"* && $TRAVIS_TAG != *"beta"* ]] && TAGS="${TAGS} -t ${DOCKER_IMAGE}:stable"
[[ $GITHUB_REF != *"alpha"* && $GITHUB_REF != *"beta"* ]] && TAGS="${TAGS} -t ${DOCKER_IMAGE}:stable"

docker buildx build --push \
--build-arg SHLINK_VERSION=${TRAVIS_TAG#?} \
--build-arg SHLINK_VERSION=${GITHUB_REF#?} \
--platform ${PLATFORMS} \
${TAGS} .

# If build branch is develop, build latest (on main branch, when there's no tag, do not build anything)
elif [[ "$TRAVIS_BRANCH" == 'develop' ]]; then
# If build branch is develop, build latest
elif [[ "$GITHUB_REF" == *"develop"* ]]; then
docker buildx build --push \
--platform ${PLATFORMS} \
-t ${DOCKER_IMAGE}:latest .
Expand Down

0 comments on commit 355ed84

Please sign in to comment.