Create and publish a Docker image #135
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
# GitHub recommends pinning actions to a commit SHA. | |
# To get a newer version, you will need to update the SHA. | |
# You can also reference a tag or branch, but the action may change without warning. | |
name: Create and publish a Docker image | |
on: | |
schedule: | |
- cron: '12 22 * * 1-5' | |
push: | |
tags: | |
- 'v[0-9]+.[0-9]+' | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3.4.0 | |
- name: Set 8.8.8.8 as dns server | |
run: | | |
sudo sed -i 's/#DNS=/DNS=8.8.8.8 8.8.4.4/g' /etc/systemd/resolved.conf | |
sudo systemctl daemon-reload | |
sudo systemctl restart systemd-networkd | |
sudo systemctl restart systemd-resolved | |
- name: downcase REPO | |
run: echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} | |
- name: Set year | |
run: echo "BUILD_YEAR=$(date +%Y)" >> $GITHUB_ENV | |
- name: Log in to Docker Hub | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Log in to the Container registry | |
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4.3.0 | |
with: | |
images: | | |
unibaktr/latex | |
ghcr.io/${{ env.REPO }} | |
- name: Build and push | |
uses: docker/build-push-action@v4.0.0 | |
with: | |
context: ./docker/ | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: YEAR=${{ env.BUILD_YEAR }} |