Merge pull request #26 from TOomaAh/main #32
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: Build and Push Docker Image | |
on: | |
push: | |
branches: | |
- dev | |
- v* | |
- latest | |
pull_request: | |
branches: | |
- v* | |
- latest | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- linux/amd64 | |
- linux/arm/v6 | |
- linux/arm/v7 | |
- linux/arm64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: bagul/goemby_exporter | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Download MaxMind DB | |
run: | | |
LICENSE_KEY=${{ secrets.MAXMIND_LICENSE_KEY }} | |
ACCOUNT_ID=${{secrets.MAXMIND_ACCOUNT_ID}} | |
# Utilisez curl pour télécharger la base de données depuis l'URL avec la clé de licence. | |
curl -o maxmind-db.tar.gz -O -J -L -u ${ACCOUNT_ID}:${LICENSE_KEY} "https://download.maxmind.com/geoip/databases/GeoLite2-City/download?suffix=tar.gz" | |
# Décompressez le fichier tar.gz (assurez-vous que vous avez `tar` installé). | |
tar zxvf maxmind-db.tar.gz | |
# Déplacez le fichier .mmdb extrait à la racine du projet. | |
mv GeoLite2-City_*/GeoLite2-City.mmdb geoip.mmdb | |
# Nettoyez les fichiers temporaires. | |
rm -rf GeoLite2-City_* maxmind-db.tar.gz | |
env: | |
LICENSE_KEY: ${{ secrets.MAXMIND_LICENSE_KEY }} | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: ${{ matrix.platform }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: type=image,name=bagul/goemby_exporter,push-by-digest=true,name-canonical=true,push=true | |
- name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
uses: actions/upload-artifact@v3 | |
with: | |
name: digests | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge: | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@v3 | |
with: | |
name: digests | |
path: /tmp/digests | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: bagul/goemby_exporter | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get version from go file | |
id: version | |
run: | | |
echo ::set-output name=version::$(grep -oP 'version = "\K[^"]+' main.go) | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
if: github.event_name != 'pull_request' | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf 'bagul/goemby_exporter@sha256:%s ' *) | |
- name: Inspect image | |
if: github.event_name != 'pull_request' | |
run: | | |
docker buildx imagetools inspect bagul/goemby_exporter:${{ steps.meta.outputs.version }} | |