• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: Build Deploy Container
2
3on:
4
5  # Always have a base image ready to go - this is a nightly build
6  schedule:
7    - cron: 0 3 * * *
8
9  # Allow manual trigger of a build
10  workflow_dispatch:
11    inputs:
12      whatever:
13        description: 'This variable does not matter, its a GHA bug.'
14
15  # On push to main we build and deploy images
16  push:
17    branches:
18      - develop
19
20  # Do build to test works on PR
21  pull_request: []
22
23  # Publish packages on release
24  release:
25    types: [published]
26
27jobs:
28  build:
29    permissions:
30      packages: write
31    strategy:
32      fail-fast: false
33      matrix:
34
35        # Dockerfiles to build, container names to use, and to tag as libabigail:latest?
36        container: [["Dockerfile.fedora", "ghcr.io/woodard/libabigail-fedora", true],
37                    ["Dockerfile.ubuntu", "ghcr.io/woodard/libabigail-ubuntu-22.04", false],
38                    ["Dockerfile.fedora-base", "ghcr.io/woodard/libabigail-fedora-base", false]]
39
40    runs-on: ubuntu-latest
41    name: Build
42    steps:
43      - name: Checkout
44        uses: actions/checkout@v3
45
46      - name: Make Space For Build
47        run: |
48          sudo rm -rf /usr/share/dotnet
49          sudo rm -rf /opt/ghc
50
51       # It's easier to reference named variables than indexes of the matrix
52      - name: Set Environment
53        env:
54          dockerfile: ${{ matrix.container[0] }}
55          uri: ${{ matrix.container[1] }}
56          isLatest: ${{ matrix.container[2] }}
57        run: |
58          echo "dockerfile=$dockerfile" >> $GITHUB_ENV
59          echo "uri=$uri" >> $GITHUB_ENV
60          echo "isLatest=$isLatest" >> $GITHUB_ENV
61
62      - name: Pull previous layers for cache
63        run: docker pull ${uri}:latest || echo "No container to pull"
64
65      - name: Build Container
66        run: |
67           container=$uri:latest
68           docker build -f docker/${dockerfile} -t ${container} .
69           if [[ "${isLatest}" == "true" ]]; then
70               docker tag ${container} ghcr.io/woodard/libabigail:latest
71           fi
72           echo "container=$container" >> $GITHUB_ENV
73
74      - name: GHCR Login
75        if: (github.event_name != 'pull_request')
76        uses: docker/login-action@v1
77        with:
78          registry: ghcr.io
79          username: ${{ github.actor }}
80          password: ${{ secrets.GITHUB_TOKEN }}
81
82      - name: Deploy
83        if: (github.event_name != 'pull_request')
84        run: |
85            docker push ${container}
86            if [[ "${isLatest}" == "true" ]]; then
87               docker push ghcr.io/woodard/libabigail:latest
88            fi
89
90      - name: Tag and Push Release
91        if: (github.event_name == 'release')
92        run: |
93            tag=${GITHUB_REF#refs/tags/}
94            echo "Tagging and releasing ${uri}:${tag}"
95            docker tag ${uri}:latest ${uri}:${tag}
96            docker push ${uri}:${tag}
97            if [[ "${isLatest}" == "true" ]]; then
98                docker tag ${uri}:latest ghcr.io/woodard/libabigail:${tag}
99                docker push ghcr.io/woodard/libabigail:${tag}
100            fi
101