#51: Using branch when building prod image #227
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | ||
on: | ||
push: | ||
branches: | ||
- '**' | ||
tags: | ||
- '!v**' | ||
release: | ||
types: | ||
- published | ||
jobs: | ||
main: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Cache Docker layers | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- | ||
name: Build a dev image | ||
id: docker_build_dev | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile.dev | ||
push: false | ||
load: true | ||
tags: transformimgs-dev | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
- | ||
name: Run tests | ||
run: | | ||
docker run --entrypoint=/go/src/github.com/Pixboost/transformimgs/test.sh -v $(pwd):/go/src/github.com/Pixboost/transformimgs transformimgs-dev | ||
- | ||
name: Code coverage | ||
run: | | ||
bash <(curl -s https://codecov.io/bash) | ||
- | ||
name: Build a prod image | ||
id: docker_build_prod | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: false | ||
load: true | ||
tags: transformimgs | ||
build-args: | | ||
Check failure on line 66 in .github/workflows/action.yml GitHub Actions / ciInvalid workflow file
|
||
"BRANCH=${{ GITHUB_HEAD_REF }}" | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
- | ||
name: Run the service | ||
run: | | ||
docker run -p 8080:8080 -d transformimgs | ||
sleep 5 | ||
- | ||
name: Smoketest | ||
run: | | ||
curl -o /dev/null -f http://localhost:8080/img/https://pixboost.com/img/homepage/hero.jpg/resize?size=x600 | ||
- | ||
name: Publish image | ||
if: ${{ github.event_name == 'release' }} | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
load: false | ||
tags: pixboost/transformimgs:${{ github.event.release.tag_name }},pixboost/transformimgs:latest | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache |