Skip to content

Commit

Permalink
Merge pull request #877 from NBISweden/feat/automated-tags
Browse files Browse the repository at this point in the history
feat: Automate prod and test image creation
  • Loading branch information
kusalananda authored Oct 12, 2023
2 parents 4ef14ad + a682be3 commit d9fde6e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 86 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/create-test-package.yml

This file was deleted.

137 changes: 98 additions & 39 deletions .github/workflows/create_packages.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,109 @@
name: Create packages
on:
pull_request:
push:
branches:
- main
types:
- closed

- develop
- main

jobs:
main:
if: github.event.pull_request.merged == true
tag:
name: generate tag
outputs:
part: ${{ steps.generate_tag.outputs.part }}
tag: ${{ steps.generate_tag.outputs.tag }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '1'
- name: Generate new tag
id: generate_tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: ${{ github.ref_name == 'develop' && 'patch' || 'minor' }}
DRY_RUN: true

push_to_registry:
strategy:
matrix:
include:
- web_url: "https://urdr.nbis.se"
redmine_url: "https://projects.nbis.se"
env: "prod"
- web_url: "https://urdr-test.nbis.se"
redmine_url: "https://urdr-test-redmine.nbis.se"
env: "test"
needs: tag
if: needs.tag.outputs.part != ''
name: Push Docker image to Github Container registry
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build and push images
working-directory: production
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
GH_ACTOR: ${{ github.actor }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_HEAD_REF: ${{ github.head_ref }}
run: |
echo "${GH_TOKEN}" | docker login ghcr.io -u "${GH_ACTOR}" --password-stdin
branch="${GH_HEAD_REF}"
for image in urdr urdr-web; do
docker pull "ghcr.io/nbisweden/$image:latest" || true
docker pull "ghcr.io/nbisweden/$image:$branch" || true
done
cat > urdr.env <<END
PUBLIC_API_URL="https://urdr.nbis.se"
PUBLIC_REDMINE_URL="https://projects.nbis.se"
END
TAG="$branch" docker-compose --env-file urdr.env build --build-arg BUILDKIT_INLINE_CACHE=1
for image in urdr urdr-web; do
docker push "ghcr.io/nbisweden/$image:$branch"
docker tag "ghcr.io/nbisweden/$image:$branch" "ghcr.io/nbisweden/$image:latest"
docker push "ghcr.io/nbisweden/$image:latest"
done
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to the Github Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/nbisweden/urdr
ghcr.io/nbisweden/urdr-web
- name: Build and push urdr
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./production/Dockerfile
push: true
tags: |
ghcr.io/nbisweden/urdr:${{ matrix.env == 'prod' && needs.tag.outputs.tag || format('{0}-test', needs.tag.outputs.tag) }}
ghcr.io/nbisweden/urdr:latest
labels: |
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
org.opencontainers.image.revision=${{ github.sha }}
- name: Build and push urdr-web
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./production/Dockerfile.nginx
build-args: |
PUBLIC_API_URL=${{ matrix.web_url }}
PUBLIC_REDMINE_URL=${{ matrix.redmine_url }}
push: true
tags: |
ghcr.io/nbisweden/urdr-web:${{ matrix.env == 'prod' && needs.tag.outputs.tag || format('{0}-test', needs.tag.outputs.tag) }}
ghcr.io/nbisweden/urdr-web:latest
labels: |
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
org.opencontainers.image.revision=${{ github.sha }}
publish_tag:
name: publish tag
needs: [push_to_registry, tag]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '1'
- name: Push tag
id: push_tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG: ${{ needs.tag.outputs.tag }}
3 changes: 0 additions & 3 deletions production/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ services:
context: ../frontend
labels:
- org.opencontainers.image.source="https://github.com/NBISweden/urdr"
args:
- PUBLIC_API_URL=${PUBLIC_API_URL}
- PUBLIC_REDMINE_URL=${PUBLIC_REDMINE_URL}
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
ports:
Expand Down

0 comments on commit d9fde6e

Please sign in to comment.